Athena IO Library
InvalidOperationException.hpp
1 // This file is part of libAthena.
2 //
3 // libAthena is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // libAthena is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with libAthena. If not, see <http://www.gnu.org/licenses/>
15 
16 #ifndef INVALID_OPERATION_EXCEPTION_HPP
17 #define INVALID_OPERATION_EXCEPTION_HPP
18 
19 #include <string>
20 #include <stdarg.h>
21 #include "Athena/Exception.hpp"
22 
23 namespace Athena
24 {
25 namespace error
26 {
37 {
38 public:
42  inline InvalidOperationException(const std::string& message, const std::string& file, const std::string& function, const int line) :
43  Exception(message, file, function, line)
44  {
45  m_exceptionName = "InvalidOperationException";
46  }
47 };
48 } // error
49 } // Athena
50 
51 #ifdef _MSC_VER
52 #define THROW_INVALID_OPERATION_EXCEPTION(args, ...) \
53  do { \
54  if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return; \
55  } else {
56 std::string msg = Athena::utility::sprintf(args, __VA_ARGS__);
57 \
58 throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__);
59 \
60 } \
61 
62 } while (0)
63 #elif defined (__GNUC__)
64 #define THROW_INVALID_OPERATION_EXCEPTION(args...) \
65  do { \
66  if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args); return; \
67  } else { std::string msg = Athena::utility::sprintf(args); \
68  throw Athena::error::InvalidOperationException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
69  } \
70  } while(0)
71 #endif
72 
73 #ifdef _MSC_VER
74 #define THROW_INVALID_OPERATION_EXCEPTIONRETURN(ret, args, ...) \
75  do { \
76  if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, __VA_ARGS__); return ret; \
77  } else {
78  std::string msg = Athena::utility::sprintf(args, __VA_ARGS__);
79 
80 \
81 throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ") + msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__);
82 \
83 } \
84 
85 } while (0)
86 #elif defined(__GNUC__)
87 #define THROW_INVALID_OPERATION_EXCEPTION_RETURN(ret, args...) \
88  do { \
89  if (atGetExceptionHandler()) {atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, args); return ret; \
90  } else { std::string msg = Athena::utility::sprintf(args); \
91  throw Athena::error::InvalidOperationException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
92  } \
93  } while(0)
94 #endif
95 #endif // INVALID_OPERATION_EXCEPTION_HPP
InvalidOperationException(const std::string &message, const std::string &file, const std::string &function, const int line)
The constructor for an InvalidOperationException.
std::string message() const
Returns the Error message of the exception.
Definition: Exception.hpp:56
An excpeption thrown on Invalid Operations calls.
The baseclass for all Exceptions.
Definition: Exception.hpp:38