00001 #ifndef SCT_SRC_EXCEPTION_H
00002 #define SCT_SRC_EXCEPTION_H
00003
00004 #include <sstream>
00005 #include <string>
00006 #include <exception>
00007
00008 #include <mrs/message.h>
00009 #include <boost/shared_ptr.hpp>
00010
00011 using std::string;
00012 using boost::shared_ptr;
00013
00014 namespace Sct {
00015
00025 class Throwable : public std::exception {
00026 public:
00031 virtual long sendToMrs(SEVERITY s) throw() = 0;
00032
00036 virtual long sendToMrs() const throw() = 0;
00037
00042 virtual void setSeverity(SEVERITY s) throw() = 0;
00043
00047 virtual SEVERITY getSeverity() const throw() = 0;
00048
00053 virtual const Throwable* getCause() const throw() = 0;
00054
00058 virtual ~Throwable() throw() {}
00059
00067 virtual shared_ptr<Throwable> clone() const throw() = 0;
00068 };
00069
00076 void setExceptionHandlers(const char* process_name) throw();
00077
00078
00093 class AbstractThrowable : public Throwable {
00094 public:
00095 virtual ~AbstractThrowable() throw() {}
00096
00102 virtual long sendToMrs(SEVERITY s) throw();
00103
00104 virtual long sendToMrs() const throw();
00105
00106 virtual void setSeverity(SEVERITY s) throw();
00107
00108 virtual SEVERITY getSeverity() const throw();
00109
00110
00116 virtual const char* what() const throw();
00117
00118 virtual const Throwable* getCause() const throw();
00119
00120 virtual shared_ptr<Throwable> clone() const throw();
00121
00122 protected:
00128 AbstractThrowable() throw();
00129
00133 virtual string getMessage() const throw();
00134
00135 void initialize(const string& id, const string& name, const string& msg, Throwable* cause, const string& file, int line) throw() ;
00136
00137 string id;
00138 string name;
00139 string msg;
00140 string file;
00141 int line;
00142 SEVERITY severity;
00143 shared_ptr<Throwable> cause;
00144
00145 mutable string text;
00146 };
00147
00153 class Exception : public AbstractThrowable {
00154 public:
00158 Exception(const string& msg, const string& file, int line) throw();
00159
00164 Exception(Throwable& cause, const string& file, int line) throw();
00165
00169 Exception(const string& msg, Throwable& cause, const string& file, int line) throw();
00170
00171 protected:
00172 Exception() throw() {}
00173 };
00174
00180 class Error : public AbstractThrowable {
00181 public:
00185 Error(const string& msg, const string& file, int line) throw();
00186
00191 Error(Throwable& cause, const string& file, int line) throw();
00192
00196 Error(const string& msg, Throwable& cause, const string& file, int line) throw();
00197
00198 protected:
00199 Error() throw() {}
00200 };
00201
00202
00203 }
00204
00205 #endif // #ifndef EXCEPTION_H