i6engine  1.0
Exceptions.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_UTILS_EXCEPTIONS_EXCEPTIONS_H__
26 #define __I6ENGINE_UTILS_EXCEPTIONS_EXCEPTIONS_H__
27 
29 #include "i6engine/utils/Logger.h"
30 
31 #include "boost/exception/all.hpp"
32 
33 #define ISIXE_THROW_SUBSYSTEM(module, message) {\
34  std::stringstream logMessageString;\
35  logMessageString << message;\
36  throw i6e::utils::exceptions::SubsystemException(module, logMessageString.str(), __FILE__, __LINE__);\
37 }
38 
39 #define ISIXE_THROW_FAILURE(module, message) {\
40  std::stringstream logMessageString;\
41  logMessageString << message;\
42  throw i6e::utils::exceptions::SystemFailureException(module, logMessageString.str(), __FILE__, __LINE__);\
43 }
44 
45 #define ISIXE_THROW_API(module, message) {\
46  std::stringstream logMessageString;\
47  logMessageString << message;\
48  throw i6e::utils::exceptions::ApiException(module, logMessageString.str(), __FILE__, __LINE__);\
49 }
50 
51 #define ISIXE_THROW_MESSAGE(module, message) {\
52  std::stringstream logMessageString;\
53  logMessageString << message;\
54  throw i6e::utils::exceptions::MessageException(module, logMessageString.str(), __FILE__, __LINE__);\
55 }
56 
57 #define ISIXE_THROW_API_COND(module, message, condition) {\
58  if (!(condition)) {\
59  ISIXE_THROW_API(module, message)\
60  }\
61 }
62 
66 #define ISIXE_THROW_API_INFO(module, message, info) {\
67  std::stringstream logMessageString;\
68  logMessageString << message << "\nPossible solutin: " << info;\
69  throw i6e::utils::exceptions::ApiException(module, logMessageString.str(), __FILE__, __LINE__);\
70 }
71 
72 namespace i6e {
73 namespace utils {
74 namespace exceptions {
75 
81  std::string message;
82  std::string module;
83  std::string file;
84  uint16_t line;
85 
86  public:
87  loginfo(const LogLevel l, const std::string & msg, const std::string & m, const std::string & f, const uint16_t li) : level(l), message(msg), module(m), file(f), line(li) {
88  }
89  };
90 
91  typedef boost::error_info<struct tag_logmessage, loginfo> excinfo_log;
92 
99  struct i6exception : virtual boost::exception, virtual std::exception {
100  public:
104  ISIXE_UTILS_API void writeLog();
105 
110 
114  ISIXE_UTILS_API virtual const char * what() const throw() override;
115 
116  protected:
117  i6exception(const LogLevel loglevel, const std::string & logmodule, const std::string & logmsg, const std::string & file, const uint16_t line);
118  };
119 
126  struct SubsystemException : virtual i6exception {
127  public:
128  ISIXE_UTILS_API SubsystemException(const std::string & logmodule, const std::string & logmsg, const std::string & file, const uint16_t line);
129 
134  };
135 
143  public:
144  ISIXE_UTILS_API SystemFailureException(const std::string & logmodule, const std::string & logmsg, const std::string & file, const uint16_t line);
145  };
146 
153  struct ApiException : virtual i6exception {
154  public:
155  ISIXE_UTILS_API ApiException(const std::string & logmodule, const std::string & logmsg, const std::string & file, const uint16_t line);
156  };
157 
164  struct MessageException : virtual i6exception {
165  public:
166  ISIXE_UTILS_API MessageException(const std::string & logmodule, const std::string & logmsg, const std::string & file, const uint16_t line);
167  };
168 
169 } /* namespace exceptions */
170 } /* namespace utils */
171 } /* namespace i6e */
172 
173 #endif /* __I6ENGINE_UTILS_EXCEPTIONS_EXCEPTIONS_H__ */
174 
ISIXE_UTILS_API void PassToMain()
Passes the exception from the subsystem to the main game loop.
LogLevel
Defines values to specify severity/importance of log message.
Definition: Logger.h:95
Internal data structure for exceptions.
Definition: Exceptions.h:79
loginfo(const LogLevel l, const std::string &msg, const std::string &m, const std::string &f, const uint16_t li)
Definition: Exceptions.h:87
ISIXE_UTILS_API int getErrorcode()
Returns the exception's errorcode or -1 if no errorcode is present.
virtual ISIXE_UTILS_API const char * what() const override
Overrides std::exception method to output message to console.
ISIXE_UTILS_API MessageException(const std::string &logmodule, const std::string &logmsg, const std::string &file, const uint16_t line)
ISIXE_UTILS_API SystemFailureException(const std::string &logmodule, const std::string &logmsg, const std::string &file, const uint16_t line)
ISIXE_UTILS_API void writeLog()
Writes the exception's logmessage.
Critical exception that cannot be repaired by a single subsystem.
Definition: Exceptions.h:142
Non-fatal, potentially reparable exception within a single subsystem.
Definition: Exceptions.h:126
Occurs when the engine detects a programmer's error.
Definition: Exceptions.h:153
boost::error_info< struct tag_logmessage, loginfo > excinfo_log
Definition: Exceptions.h:91
Base type for custom exceptions.
Definition: Exceptions.h:99
ISIXE_UTILS_API SubsystemException(const std::string &logmodule, const std::string &logmsg, const std::string &file, const uint16_t line)
#define ISIXE_UTILS_API
Occurs when a wrong message is detected.
Definition: Exceptions.h:164
i6exception(const LogLevel loglevel, const std::string &logmodule, const std::string &logmsg, const std::string &file, const uint16_t line)
ISIXE_UTILS_API ApiException(const std::string &logmodule, const std::string &logmsg, const std::string &file, const uint16_t line)