m2etis  0.4
Exceptions.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef __M2ETIS_UTIL_EXCEPTIONS_H__
23 #define __M2ETIS_UTIL_EXCEPTIONS_H__
24 
25 #include "m2etis/util/Logger.h"
27 
28 #include "boost/exception/all.hpp"
29 
33 #define M2ETIS_THROW_FAILURE(module, message, errorcode) {\
34  throw m2etis::util::SystemFailureException(module, message, __FILE__, __LINE__, errorcode);\
35  }
36 
40 #define M2ETIS_THROW_API(module, message) {\
41  throw m2etis::util::ApiException(module, message, __FILE__, __LINE__);\
42  }
43 
44 namespace m2etis {
45 namespace util {
46 
52  std::string message;
53  std::string module;
54  std::string file;
55  int line;
56  int errorcode;
57 
58  public:
59  loginfo(const log::LogLevel l, const std::string msg, const std::string m, const std::string f, int li)
60  : level(l), message(msg), module(m), file(f), line(li), errorcode(-1) {
61  }
62 
63  loginfo(const log::LogLevel l, const std::string msg, const std::string m, const std::string f, int li, int errcode)
64  : level(l), message(msg), module(m), file(f), line(li), errorcode(errcode) {
65  }
66  };
67 
68  typedef boost::error_info<struct tag_logmessage, loginfo> excinfo_log;
69 
76  struct m2exception : virtual boost::exception, virtual std::exception {
77  public:
81  M2ETIS_API void writeLog();
82 
87 
91  M2ETIS_API virtual const char * what() const throw();
92 
96  M2ETIS_API void PassToMain();
97 
98  protected:
99  M2ETIS_API m2exception(const util::log::LogLevel loglevel, const std::string & logmodule, const std::string & logmsg, const std::string & file, int line);
100 
101  M2ETIS_API m2exception(const util::log::LogLevel loglevel, const std::string & logmodule, const std::string & logmsg, const std::string & file, int line, int errorcode);
102  };
103 
104 
112  public:
113  M2ETIS_API SystemFailureException(const std::string & logmodule, const std::string & logmsg, const std::string & file, const int line, const int errorcode);
114  };
115 
122  struct ApiException : virtual m2exception {
123  public:
124  M2ETIS_API ApiException(const std::string & logmodule, const std::string & logmsg, const std::string & file, const int line);
125  };
126 
127 } /* namespace util */
128 } /* namespace m2etis */
129 
130 #endif /* __M2ETIS_UTIL_EXCEPTIONS_H__ */
131 
Occurs when the engine detects a programmer's error.
Definition: Exceptions.h:122
std::string module
Definition: Exceptions.h:53
M2ETIS_API m2exception(const util::log::LogLevel loglevel, const std::string &logmodule, const std::string &logmsg, const std::string &file, int line)
#define M2ETIS_API
std::string file
Definition: Exceptions.h:54
LogLevel
Defines values to specify severity/importance of log message.
Definition: Logger.h:86
loginfo(const log::LogLevel l, const std::string msg, const std::string m, const std::string f, int li)
Definition: Exceptions.h:59
virtual M2ETIS_API const char * what() const
Overrides std::exception method to output message to console.
M2ETIS_API ApiException(const std::string &logmodule, const std::string &logmsg, const std::string &file, const int line)
M2ETIS_API void PassToMain()
writes the error message to the ExceptionQueue
boost::error_info< struct tag_logmessage, loginfo > excinfo_log
Definition: Exceptions.h:68
Internal data structure for exceptions.
Definition: Exceptions.h:50
util::log::LogLevel level
Definition: Exceptions.h:51
M2ETIS_API int getErrorcode()
Returns the exception's errorcode or -1 if no errorcode is present.
loginfo(const log::LogLevel l, const std::string msg, const std::string m, const std::string f, int li, int errcode)
Definition: Exceptions.h:63
std::string message
Definition: Exceptions.h:52
Critical exception that cannot be repaired by a single subsystem.
Definition: Exceptions.h:111
M2ETIS_API SystemFailureException(const std::string &logmodule, const std::string &logmsg, const std::string &file, const int line, const int errorcode)
M2ETIS_API void writeLog()
Writes the exception's logmessage.