main.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include <stdexcept>
22 #include <iostream>
23 #include <cstdlib>
24 #include <mia/core/msgstream.hh>
25 
26 
27 #define MIA_MAIN(callback) \
28  int main( int argc, char *argv[] ) \
29  { \
30  try { \
31  auto verb = getenv("MIA_INITIAL_VERBOSITY"); \
32  if (verb) { \
33  auto level = mia::g_verbose_dict.get_value(verb); \
34  mia::vstream::instance().set_verbosity(level); \
35  } \
36  return callback(argc, argv); \
37  } \
38  catch (const std::runtime_error &e){ \
39  std::cerr << "\n" << argv[0] << " runtime error: " << e.what() << std::endl; \
40  } \
41  catch (const std::invalid_argument &e){ \
42  std::cerr << "\n" << argv[0] << " invalid argument: " << e.what() << std::endl; \
43  } \
44  catch (const std::logic_error &e){ \
45  std::cerr << "\n" << argv[0] << " logic error: " << e.what() << std::endl; \
46  } \
47  catch (const std::exception& e){ \
48  std::cerr << "\n" << argv[0] << " error: " << e.what() << std::endl; \
49  } \
50  catch (...){ \
51  std::cerr << "\n" << argv[0] << " unknown exception" << std::endl; \
52  } \
53  return EXIT_FAILURE; \
54  }