File indexing completed on 2024-04-06 11:56:53
0001 #ifndef __EXCEPTIONS__
0002 #define __EXCEPTIONS__
0003
0004 #include <cstdlib>
0005 #include <iostream>
0006 #include <exception>
0007 #include <string>
0008
0009 #include "boost/exception/exception.hpp"
0010 #include "boost/exception/diagnostic_information.hpp"
0011
0012 #include "boost/property_tree/exceptions.hpp"
0013 #include "boost/filesystem.hpp"
0014
0015
0016
0017
0018 namespace AllInOneConfig {
0019
0020 class ConfigError : public std::exception {
0021 const char *msg;
0022 const char *what() const throw() override { return msg; }
0023
0024 public:
0025 ConfigError(const char *m) : msg(m) {}
0026 };
0027
0028 inline std::string colorify(std::string s) {
0029 const char *red = "\x1B[31m" ;
0030 return red + s ;
0031 }
0032
0033 template <int FUNC(int, char **)>
0034 int exceptions(int argc, char *argv[]) {
0035 try {
0036 return FUNC(argc, argv);
0037 } catch (const boost::exception &e) {
0038 std::cerr << colorify("Boost exception: ") << boost::diagnostic_information(e);
0039 throw;
0040 } catch (const boost::property_tree::ptree_bad_data &e) {
0041 std::cerr << colorify("Property Tree Bad Data Error: ") << e.data<std::string>() << '\n';
0042 } catch (const boost::property_tree::ptree_bad_path &e) {
0043 std::cerr << colorify("Property Tree Bad Path Error: ") << e.path<std::string>() << '\n';
0044 } catch (const boost::property_tree::ptree_error &e) {
0045 std::cerr << colorify("Property Tree Error: ") << e.what() << '\n';
0046 } catch (const boost::filesystem::filesystem_error &e) {
0047 std::cerr << colorify("Filesystem Error:") << e.what() << '\n';
0048 } catch (const std::logic_error &e) {
0049 std::cerr << colorify("Logic Error: ") << e.what() << '\n';
0050 } catch (const std::exception &e) {
0051 std::cerr << colorify("Standard Error: ") << e.what() << '\n';
0052 }
0053 return EXIT_FAILURE;
0054 }
0055
0056 }
0057 #endif