symengine_exception.h
1 #ifndef SYMENGINE_EXCEPTION_H
2 #define SYMENGINE_EXCEPTION_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 typedef enum {
9  SYMENGINE_NO_EXCEPTION = 0,
10  SYMENGINE_RUNTIME_ERROR = 1,
11  SYMENGINE_DIV_BY_ZERO = 2,
12  SYMENGINE_NOT_IMPLEMENTED = 3,
13  SYMENGINE_DOMAIN_ERROR = 4,
14  SYMENGINE_PARSE_ERROR = 5,
15  SYMENGINE_SERIALIZATION_ERROR = 6,
16 } symengine_exceptions_t;
17 
18 #ifdef __cplusplus
19 }
20 #endif
21 
22 #ifdef __cplusplus
23 
24 #include <exception>
25 #include <string>
26 
27 namespace SymEngine
28 {
29 
30 class SymEngineException : public std::exception
31 {
32  std::string m_msg;
33  symengine_exceptions_t ec;
34 
35 public:
36  SymEngineException(const std::string &msg, symengine_exceptions_t error)
37  : m_msg(msg), ec(error)
38  {
39  }
40  SymEngineException(const std::string &msg)
41  : SymEngineException(msg, SYMENGINE_RUNTIME_ERROR)
42  {
43  }
44  const char *what() const throw() override
45  {
46  return m_msg.c_str();
47  }
48  symengine_exceptions_t error_code()
49  {
50  return ec;
51  }
52 };
53 
54 class DivisionByZeroError : public SymEngineException
55 {
56 public:
57  DivisionByZeroError(const std::string &msg)
58  : SymEngineException(msg, SYMENGINE_DIV_BY_ZERO)
59  {
60  }
61 };
62 
63 class NotImplementedError : public SymEngineException
64 {
65 public:
66  NotImplementedError(const std::string &msg)
67  : SymEngineException(msg, SYMENGINE_NOT_IMPLEMENTED)
68  {
69  }
70 };
71 
72 class DomainError : public SymEngineException
73 {
74 public:
75  DomainError(const std::string &msg)
76  : SymEngineException(msg, SYMENGINE_DOMAIN_ERROR)
77  {
78  }
79 };
80 
81 class ParseError : public SymEngineException
82 {
83 public:
84  ParseError(const std::string &msg)
85  : SymEngineException(msg, SYMENGINE_PARSE_ERROR)
86  {
87  }
88 };
89 
90 class SerializationError : public SymEngineException
91 {
92 public:
93  SerializationError(const std::string &msg)
94  : SymEngineException(msg, SYMENGINE_SERIALIZATION_ERROR)
95  {
96  }
97 };
98 } // namespace SymEngine
99 #endif // __cplusplus
100 #endif // SYMENGINE_EXCEPTION_H
T c_str(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19