00001
00002
00003
00004
00005
00006
00007 #include <exception>
00008 #include <stdexcept>
00009
00010 struct rt_exception {
00011 virtual void rethrow() = 0;
00012 virtual rt_exception* copy() const = 0;
00013 virtual const char* what() const throw() = 0;
00014 virtual ~rt_exception() throw() {}
00015 };
00016
00017 #if 1
00018 template <class T>
00019 struct rethrowable : public T, public rt_exception {
00020 typedef rethrowable<T> self;
00021
00022 rethrowable() {}
00023 rethrowable(const rethrowable& x) : T(x) {}
00024 virtual ~rethrowable() throw() {}
00025
00026 template <class A0> rethrowable(const A0& x) : T(x) {}
00027 template <class A0, class A1> rethrowable(A0 x0, A1 x1) : T(x0, x1) {}
00028 template <class A0, class A1, class A2> rethrowable(A0 x0, A1 x1, A2 x2)
00029 : T(x0, x1, x2) {}
00030
00031 virtual void rethrow() { throw(*this); }
00032 virtual rt_exception *copy() const { return new self(*this); }
00033 virtual const char* what() const throw() { return T::what(); }
00034 };
00035
00036 typedef rethrowable<std::logic_error> rt_logic_error;
00037 typedef rethrowable<std::domain_error> rt_domain_error;
00038 typedef rethrowable<std::invalid_argument> rt_invalid_argument;
00039 typedef rethrowable<std::length_error> rt_length_error;
00040 typedef rethrowable<std::out_of_range> rt_out_of_range;
00041
00042 typedef rethrowable<std::runtime_error> rt_runtime_error;
00043 typedef rethrowable<std::range_error> rt_range_error;
00044 typedef rethrowable<std::overflow_error> rt_overflow_error;
00045 typedef rethrowable<std::underflow_error> rt_underflow_error;
00046
00047 #else
00048
00049 struct rt_logic_error : public rt_exception, public std::logic_error {
00050 virtual void rethrow() { throw *this; }
00051 virtual rt_exception* copy() const
00052 { return new rt_logic_error(*this); }
00053 virtual const char* what() const throw()
00054 { return std::logic_error::what(); }
00055 rt_logic_error(std::string s) : std::logic_error(s) {}
00056 };
00057 struct rt_runtime_error : public rt_exception, public std::runtime_error {
00058 virtual void rethrow() { throw *this; }
00059 virtual rt_exception* copy() const
00060 { return new rt_runtime_error(*this); }
00061 virtual const char* what() const throw()
00062 { return std::runtime_error::what(); }
00063 rt_runtime_error(std::string s) : std::runtime_error(s) {}
00064 };
00065
00066 #endif
00067
00068 class thread_error : public std::logic_error {
00069 public:
00070 thread_error(const std::string& s) : std::logic_error(s) {}
00071 };
00072
00073
00074