00001
00002
00003 #ifndef KERNEL_JAFAR_EXCEPTION_HPP
00004 #define KERNEL_JAFAR_EXCEPTION_HPP
00005
00006 #include <string>
00007
00008 #include <list>
00009
00010 #include <iostream>
00011
00012 #include "kernel/jafarMacro.hpp"
00013
00014 namespace jafar {
00015
00016 namespace kernel {
00017
00018
00019
00020 std::string get_system_trace ();
00021 void print_system_trace();
00022
00031 class Exception {
00032
00033 public:
00034
00042 virtual std::string what() const throw();
00043
00047 void addTrace(std::string const& module_, std::string const& file_, int line_, std::string const& message_ = "");
00048
00049 Exception(const std::string& message_,
00050 const std::string& module_, const std::string& id_,
00051 const std::string& file_, int line_) throw();
00052
00053 virtual ~Exception() throw();
00054
00055 protected:
00056
00058 std::string _what;
00059
00063 std::list<std::string> trace;
00064
00065 friend std::ostream& operator <<(std::ostream& s, const Exception& e);
00066
00067 };
00068
00069 std::ostream& operator <<(std::ostream& s, const Exception& e);
00070
00077 class JafarException : public jafar::kernel::Exception {
00078
00079 public:
00080
00082 enum ExceptionId {
00083 ASSERT,
00084 PRECONDITION,
00085 POSTCONDITION,
00086 INVARIANT,
00087 RUN_TIME,
00088 IO_STREAM,
00089 NUMERIC,
00090 INVALID_PARAM
00091 };
00092
00102 JafarException(ExceptionId id_, const std::string& message_,
00103 const std::string& module_, const std::string& file_, int line_) throw();
00104
00105 virtual ~JafarException() throw();
00106
00107 ExceptionId getExceptionId() const throw();
00108
00109 protected:
00110
00111 ExceptionId id;
00112
00113 static std::string exceptionIdToString(ExceptionId id_) throw();
00114
00115 };
00116
00122 template<typename T>
00123 class InvalidParamException : public JafarException {
00124
00125 public:
00126
00127 InvalidParamException(const T& value, const std::string& message_,
00128 const std::string& module_, const std::string& file_, int line_) :
00129 JafarException(INVALID_PARAM, message_, module_, file_, line_),
00130 m_value(value) {}
00131
00133 T value() const {return m_value;}
00134
00135 private:
00136
00137 T m_value;
00138
00139 };
00140
00146 template <typename T>
00147 void throwInvalidParamException(const T& value, const std::string& message_,
00148 const std::string& module_, const std::string& file_, int line_)
00149 {
00150 throw InvalidParamException<T>(value, message_,
00151 module_, file_, line_);
00152 }
00153
00154 }
00155 }
00156
00157
00158 #include "kernel/jafarMacro.hpp"
00159
00160 #endif // KERNEL_JAFAR_EXCEPTION_HPP