00001 #ifndef s11n_net_s11n_v1_1_EXCEPTION_HPP_INCLUDED 00002 #define s11n_net_s11n_v1_1_EXCEPTION_HPP_INCLUDED 1 00003 00004 #include <string> 00005 #include <exception> 00006 #include <s11n.net/s11n/s11n_config.hpp> 00007 00008 //Added by Damien to make Windows compile work 00009 #include <s11n.net/s11n/export.hpp> // S11N_EXPORT_API 00010 00011 namespace s11n { 00012 00013 /** 00014 The base-most exception type used by s11n. 00015 */ 00016 //Added by Damien to make Windows compile work 00017 struct S11N_EXPORT_API s11n_exception : public std::exception 00018 { 00019 public: 00020 virtual ~s11n_exception() throw() {} 00021 // removed in 1.2.6: explicit s11n_exception( const std::string & What ); 00022 00023 /** 00024 Creates an exception with the given formatted 00025 what() string. Takes a printf-like format 00026 string. If the expanded string is longer than some 00027 arbitrarily-chosen internal limit [hint: 2k bytes] 00028 then it is truncated. 00029 00030 If you get overload ambiguities with the 00031 std::string-argument ctor, this is because you've 00032 passed a (char const *) string to those ctors and 00033 relied on implicit conversion to std::string. 00034 Simply wrapping those c-strings in std::string 00035 ctors should get around the problem. 00036 00037 Historical note: 00038 00039 This ctor, introduced in version 1.2.6, conflicted 00040 with an older 3-arg ctor taking (std::string,char 00041 const *,uint) arguments, but this one is far more 00042 flexible, so the older was removed. We also had 00043 ctor taking a std::string, but that was removed 00044 to avoid additional ambiguities. 00045 */ 00046 explicit s11n_exception( const char *format, ... ); 00047 00048 /** 00049 Returns the 'what' string passed to the ctor. 00050 */ 00051 virtual const char * what() const throw(); 00052 protected: 00053 /** 00054 Intended to be used by ctors. 00055 */ 00056 void what( std::string const & ) throw(); 00057 s11n_exception(); 00058 private: 00059 std::string m_what; 00060 }; 00061 00062 /** 00063 An exception type for classloader-related exceptions. These 00064 need to be caught separately from s11n_exceptions in some 00065 cases because sometimes a classloader can try other 00066 alternatives on an error. 00067 */ 00068 struct S11N_EXPORT_API factory_exception : public s11n_exception 00069 { 00070 public: 00071 virtual ~factory_exception() throw() {} 00072 // removed in 1.2.6: explicit factory_exception( const std::string & What ) : s11n_exception( What ) {} 00073 explicit factory_exception( const char *format, ... ); 00074 // factory_exception( const std::string & What, const std::string & file, unsigned int line ) : s11n_exception( What,file,line ) {} 00075 }; 00076 00077 00078 /** 00079 Really for use by clients, i/o layers, and s11nlite, not by 00080 the s11n core. 00081 */ 00082 struct io_exception : public s11n_exception 00083 { 00084 public: 00085 virtual ~io_exception() throw() {} 00086 // removed in 1.2.6: explicit io_exception( const std::string & What ) : s11n_exception( What ) {} 00087 explicit io_exception( const char *format, ... ); 00088 }; 00089 00090 00091 } // namespace s11n 00092 00093 // /** 00094 // S11N_THROW(WHAT) simply throws s11n_exception(WHAT,__FILE__,__LINE__). 00095 // */ 00096 // #define S11N_THROW(WHAT) throw ::s11n::s11n_exception(std::string(WHAT),__FILE__,__LINE__) 00097 00098 #endif // s11n_net_s11n_v1_1_EXCEPTION_HPP_INCLUDED