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_exceptions_t;
16 
17 #ifdef __cplusplus
18 }
19 #endif
20 
21 #ifdef __cplusplus
22 
23 #include <exception>
24 #include <string>
25 
26 namespace SymEngine
27 {
28 
29 class SymEngineException : public std::exception
30 {
31  std::string m_msg;
32  symengine_exceptions_t ec;
33 
34 public:
35  SymEngineException(const std::string &msg, symengine_exceptions_t error)
36  : m_msg(msg), ec(error)
37  {
38  }
39  SymEngineException(const std::string &msg)
40  : SymEngineException(msg, SYMENGINE_RUNTIME_ERROR)
41  {
42  }
43  const char *what() const throw()
44  {
45  return m_msg.c_str();
46  }
47  symengine_exceptions_t error_code()
48  {
49  return ec;
50  }
51 };
52 
53 class DivisionByZeroError : public SymEngineException
54 {
55 public:
56  DivisionByZeroError(const std::string &msg)
57  : SymEngineException(msg, SYMENGINE_DIV_BY_ZERO)
58  {
59  }
60 };
61 
62 class NotImplementedError : public SymEngineException
63 {
64 public:
65  NotImplementedError(const std::string &msg)
66  : SymEngineException(msg, SYMENGINE_NOT_IMPLEMENTED)
67  {
68  }
69 };
70 
71 class DomainError : public SymEngineException
72 {
73 public:
74  DomainError(const std::string &msg)
75  : SymEngineException(msg, SYMENGINE_DOMAIN_ERROR)
76  {
77  }
78 };
79 
80 class ParseError : public SymEngineException
81 {
82 public:
83  ParseError(const std::string &msg)
84  : SymEngineException(msg, SYMENGINE_PARSE_ERROR)
85  {
86  }
87 };
88 } // namespace SymEngine
89 #endif // __cplusplus
90 #endif // SYMENGINE_EXCEPTION_H
T c_str(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19