exception.hpp

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

Generated on Wed Jun 4 21:41:59 2008 for libs11n-1.2.7 by  doxygen 1.5.3