DiaDes  0.1
DIAgnosis of Discrete-Event System
Exceptions.hh
Go to the documentation of this file.
1 #ifndef __DIADES__UTILS__EXCEPTION__HH
2 #define __DIADES__UTILS__EXCEPTION__HH
3 
4 #include<string>
5 #include<exception>
7 
8 
9 
10 using std::string;
11 using std::exception;
12 
13 namespace Diades
14 {
15 
16 namespace Utils
17 {
18 
19 
20  template<typename Object>
21  class Exception: public exception
22  {
23  private:
24  string _what;
25 
26  public:
27  Exception(const string & whatArg):exception(),_what(Object::typeName() + " exception: \"" + whatArg + "\""){}
28  Exception(const Msg & msg):exception(),_what(Object::typeName() + " exception: \"" + msg.str() + "\""){}
29  Exception(const string & whatArg, const exception & e):
30  exception(),_what(Object::typeName() + " exception: \"" + whatArg + "\"")
31  {
32  _what += " due to \n";
33  _what += e.what();
34  }
35  Exception(const Msg & msg, const exception & e):
36  exception(),_what(Object::typeName() + " exception: \"" + msg.str() + "\"")
37  {
38  _what += " due to \n";
39  _what += e.what();
40  }
41  virtual const char * what() const throw()
42  {
43  return _what.c_str();
44  }
45 
46  virtual ~Exception() throw() {};
47 
48  };
49 
50 
51  class FunctionException: public exception
52  {
53  private:
54  string _what;
55 
56  public:
57  FunctionException(const string & whatArg):exception(),_what("A function exception has been thrown: \"" + whatArg + "\""){}
58  FunctionException(const Msg & msg):exception(),_what("A function exception has been thrown: \"" + msg.str() + "\""){}
59 
60  FunctionException(const string & functionName, const string & whatArg):exception(),_what("Function " + functionName + " throws the exception:\"" + whatArg + "\""){}
61 
62  FunctionException(const string & functionName, const string & whatArg, const exception & e):exception(),_what("Function " + functionName + " throws the exception:\"" + whatArg + "\""){
63  _what += " due to \n";
64  _what += e.what();
65  }
66  FunctionException(const string & functionName, const Msg & whatArg, const exception & e):exception(),_what("Function " + functionName + " throws the exception:\"" + whatArg.str() + "\""){
67  _what += " due to \n";
68  _what += e.what();
69  }
70 
71  FunctionException(const string & functionName, const Msg & whatArg):exception(),_what("Function " + functionName + " throws the exception:\"" + whatArg.str() + "\""){}
72 
73  virtual const char * what() const throw()
74  {
75  return _what.c_str();
76  }
77 
78  virtual ~FunctionException() throw() {};
79  };
80 
81 
82 
83 
84  class Failure: public exception
85  {
86  private:
87  string _what;
88 
89  public:
90 
91  Failure(const string & functionName):exception(),_what("Function " + functionName + " throws a failure exception."){}
92 
93 
94 
95  Failure(const string & functionName,
96  const exception & e):exception(),
97  _what("Function " + functionName + " throws a failure exception"){
98  _what += " due to \n";
99  _what += e.what();
100  }
101 
102 
103  virtual const char * what() const throw()
104  {
105  return _what.c_str();
106  }
107 
108  virtual ~Failure() throw() {};
109  };
110 
111 
112 };
113 
114 
115 };
116 #endif
virtual const char * what() const
Definition: Exceptions.hh:41
Failure(const string &functionName, const exception &e)
Definition: Exceptions.hh:95
FunctionException(const string &whatArg)
Definition: Exceptions.hh:57
virtual const char * what() const
Definition: Exceptions.hh:73
FunctionException(const string &functionName, const Msg &whatArg, const exception &e)
Definition: Exceptions.hh:66
Failure(const string &functionName)
Definition: Exceptions.hh:91
FunctionException(const Msg &msg)
Definition: Exceptions.hh:58
Exception(const string &whatArg, const exception &e)
Definition: Exceptions.hh:29
FunctionException(const string &functionName, const Msg &whatArg)
Definition: Exceptions.hh:71
Namespace of the Diades project.
Exception(const Msg &msg, const exception &e)
Definition: Exceptions.hh:35
Exception(const string &whatArg)
Definition: Exceptions.hh:27
FunctionException(const string &functionName, const string &whatArg)
Definition: Exceptions.hh:60
Exception(const Msg &msg)
Definition: Exceptions.hh:28
FunctionException(const string &functionName, const string &whatArg, const exception &e)
Definition: Exceptions.hh:62
virtual const char * what() const
Definition: Exceptions.hh:103
boost::format Msg
Definition: Verbose.hh:42