diff --git a/example/cloning_1.cpp b/example/cloning_1.cpp index b3b9d90..55e8479 100644 --- a/example/cloning_1.cpp +++ b/example/cloning_1.cpp @@ -16,7 +16,7 @@ class file_read_error: public boost::exception { }; void file_read( FILE * f, void * buffer, size_t size ) - { + { if( size!=fread(buffer,1,size,f) ) throw boost::enable_exception_cloning(file_read_error()) << errno_info(errno); - } + } diff --git a/example/cloning_2.cpp b/example/cloning_2.cpp index 2686004..157f0b5 100644 --- a/example/cloning_2.cpp +++ b/example/cloning_2.cpp @@ -13,27 +13,27 @@ void do_work(); //throws cloning-enabled boost::exceptions void worker_thread( boost::exception_ptr & error ) - { - try - { + { + try + { do_work(); error = boost::exception_ptr(); - } + } catch( - boost::exception & e ) - { + boost::exception & e ) + { error = boost::clone_exception(e); - } - } + } + } // void work() - { + { boost::exception_ptr error; boost::thread t( boost::bind(worker_thread,boost::ref(error)) ); t.join(); if( error ) boost::rethrow_exception(error); - } + } diff --git a/example/enable_error_info.cpp b/example/enable_error_info.cpp index 0be25b3..0470bf1 100644 --- a/example/enable_error_info.cpp +++ b/example/enable_error_info.cpp @@ -17,19 +17,19 @@ typedef boost::error_info std_range_index; template class my_container - { - public: + { + public: - size_t size() const; + size_t size() const; T const & - operator[]( size_t i ) const - { + operator[]( size_t i ) const + { if( i > size() ) throw boost::enable_error_info(std::range_error("Index out of range")) << std_range_min(0) << std_range_max(size()) << std_range_index(i); - //.... - } - }; + //.... + } + }; diff --git a/example/error_info_1.cpp b/example/error_info_1.cpp index 415cc3e..b67f728 100644 --- a/example/error_info_1.cpp +++ b/example/error_info_1.cpp @@ -16,21 +16,21 @@ class my_error: public boost::exception, public std::exception { }; //(2) void f() - { + { throw my_error() << errno_info(errno); //(3) - } - + } + void g() - { + { try - { + { f(); - } + } catch( - my_error & x ) - { - if( boost::shared_ptr err=boost::get_error_info(x) ) + my_error & x ) + { + if( boost::shared_ptr err=boost::get_error_info(x) ) std::cerr << "Error code: " << *err; - } - } + } + } diff --git a/example/error_info_2.cpp b/example/error_info_2.cpp index c95aa62..7464aaf 100644 --- a/example/error_info_2.cpp +++ b/example/error_info_2.cpp @@ -18,10 +18,10 @@ class file_read_error: public boost::exception { }; void file_read( FILE * f, void * buffer, size_t size ) - { + { if( size!=fread(buffer,1,size,f) ) throw file_read_error() << errno_info(errno); - } + } // @@ -32,18 +32,18 @@ void file_read( FILE * f, void * buffer, size_t size ); void parse_file( char const * file_name ) - { + { boost::shared_ptr f = file_open(file_name,"rb"); assert(f); try - { - char buf[1024]; + { + char buf[1024]; file_read( f.get(), buf, sizeof(buf) ); - } + } catch( - boost::exception & e ) - { + boost::exception & e ) + { e << file_name_info(file_name); throw; - } - } + } + } diff --git a/example/example_io.cpp b/example/example_io.cpp index 57d31de..2fb0dd4 100644 --- a/example/example_io.cpp +++ b/example/example_io.cpp @@ -8,7 +8,7 @@ // //The documentation for boost::exception can be found at: // -// http://www.revergestudios.com/boost-exception/boost-exception.htm. +// http://www.revergestudios.com/boost-exception/boost-exception.htm. // //The output from this program can vary depending on the compiler/OS combination. @@ -33,23 +33,23 @@ size_t const data_size = sizeof(data); class error: //Base for all exception objects we throw. - public std::exception, - public boost::exception - { - public: + public std::exception, + public boost::exception + { + public: - char const * - what() const throw() - { - return boost::exception::what(); - } + char const * + what() const throw() + { + return boost::exception::what(); + } - protected: + protected: - ~error() throw() - { - } - }; + ~error() throw() + { + } + }; class open_error: public error { }; class read_error: public error { }; @@ -62,154 +62,154 @@ class fwrite_error: public write_error { }; boost::shared_ptr my_fopen( char const * name, char const * mode ) - { - if( FILE * f = ::fopen(name,mode) ) - return boost::shared_ptr(f,fclose); - else - throw fopen_error() << BOOST_ERROR_INFO << - errno_info(errno) << - file_name_info(name) << - open_mode_info(mode) << - function_info("fopen"); - } + { + if( FILE * f = ::fopen(name,mode) ) + return boost::shared_ptr(f,fclose); + else + throw fopen_error() << BOOST_ERROR_INFO << + errno_info(errno) << + file_name_info(name) << + open_mode_info(mode) << + function_info("fopen"); + } void my_fread( void * buffer, size_t size, size_t count, boost::shared_ptr const & stream ) - { - assert(stream); - if( count!=fread(buffer,size,count,stream.get()) || ferror(stream.get()) ) - throw fread_error() << BOOST_ERROR_INFO << - function_info("fread") << - errno_info(errno) << - file_stream_info(boost::weak_ptr(stream)); - } + { + assert(stream); + if( count!=fread(buffer,size,count,stream.get()) || ferror(stream.get()) ) + throw fread_error() << BOOST_ERROR_INFO << + function_info("fread") << + errno_info(errno) << + file_stream_info(boost::weak_ptr(stream)); + } void my_fwrite( void const * buffer, size_t size, size_t count, boost::shared_ptr const & stream ) - { - assert(stream); - if( count!=fwrite(buffer,size,count,stream.get()) || ferror(stream.get()) ) - throw fwrite_error() << BOOST_ERROR_INFO << - function_info("fwrite") << - errno_info(errno) << - file_stream_info(boost::weak_ptr(stream)); - } + { + assert(stream); + if( count!=fwrite(buffer,size,count,stream.get()) || ferror(stream.get()) ) + throw fwrite_error() << BOOST_ERROR_INFO << + function_info("fwrite") << + errno_info(errno) << + file_stream_info(boost::weak_ptr(stream)); + } void reset_file( char const * file_name ) - { - (void) my_fopen(file_name,"wb"); - } + { + (void) my_fopen(file_name,"wb"); + } void create_data( char const * file_name ) - { - boost::shared_ptr f = my_fopen(file_name,"wb"); - my_fwrite( data, 1, data_size, f ); - } + { + boost::shared_ptr f = my_fopen(file_name,"wb"); + my_fwrite( data, 1, data_size, f ); + } void copy_data( char const * src_file_name, char const * dst_file_name ) - { - boost::shared_ptr src = my_fopen(src_file_name,"rb"); - boost::shared_ptr dst = my_fopen(dst_file_name,"wb"); - try - { - char buffer[data_size]; - my_fread( buffer, 1, data_size, src ); - my_fwrite( buffer, 1, data_size, dst ); - } - catch( - boost::exception & x ) - { - if( boost::shared_ptr const> f=boost::get_error_info(x) ) - if( boost::shared_ptr fs = f->lock() ) - { - if( fs==src ) - x << file_name_info(src_file_name); - else if( fs==dst ) - x << file_name_info(dst_file_name); - } - x << - file_name_src_info(src_file_name) << - file_name_dst_info(dst_file_name); - throw; - } - } + { + boost::shared_ptr src = my_fopen(src_file_name,"rb"); + boost::shared_ptr dst = my_fopen(dst_file_name,"wb"); + try + { + char buffer[data_size]; + my_fread( buffer, 1, data_size, src ); + my_fwrite( buffer, 1, data_size, dst ); + } + catch( + boost::exception & x ) + { + if( boost::shared_ptr const> f=boost::get_error_info(x) ) + if( boost::shared_ptr fs = f->lock() ) + { + if( fs==src ) + x << file_name_info(src_file_name); + else if( fs==dst ) + x << file_name_info(dst_file_name); + } + x << + file_name_src_info(src_file_name) << + file_name_dst_info(dst_file_name); + throw; + } + } void dump_copy_info( boost::exception const & x ) - { - if( boost::shared_ptr src = boost::get_error_info(x) ) - std::cout << "Source file name: " << *src << "\n"; - if( boost::shared_ptr dst = boost::get_error_info(x) ) - std::cout << "Destination file name: " << *dst << "\n"; - } + { + if( boost::shared_ptr src = boost::get_error_info(x) ) + std::cout << "Source file name: " << *src << "\n"; + if( boost::shared_ptr dst = boost::get_error_info(x) ) + std::cout << "Destination file name: " << *dst << "\n"; + } void dump_file_info( boost::exception const & x ) - { - if( boost::shared_ptr fn = boost::get_error_info(x) ) - std::cout << "Source file name: " << *fn << "\n"; - } + { + if( boost::shared_ptr fn = boost::get_error_info(x) ) + std::cout << "Source file name: " << *fn << "\n"; + } void dump_clib_info( boost::exception const & x ) - { - if( boost::shared_ptr err=boost::get_error_info(x) ) - std::cout << "OS error: " << *err << "\n"; - if( boost::shared_ptr fn=boost::get_error_info(x) ) - std::cout << "Failed function: " << *fn << "\n"; - } + { + if( boost::shared_ptr err=boost::get_error_info(x) ) + std::cout << "OS error: " << *err << "\n"; + if( boost::shared_ptr fn=boost::get_error_info(x) ) + std::cout << "Failed function: " << *fn << "\n"; + } void dump_all_info( boost::exception const & x ) - { - std::cout << "-------------------------------------------------\n"; - dump_copy_info(x); - dump_file_info(x); - dump_clib_info(x); - std::cout << "\nOutput from what():\n"; - std::cout << x.what(); - } + { + std::cout << "-------------------------------------------------\n"; + dump_copy_info(x); + dump_file_info(x); + dump_clib_info(x); + std::cout << "\nOutput from what():\n"; + std::cout << x.what(); + } int main() - { - try - { - create_data( "tmp1.txt" ); - copy_data( "tmp1.txt", "tmp2.txt" ); //This should succeed. + { + try + { + create_data( "tmp1.txt" ); + copy_data( "tmp1.txt", "tmp2.txt" ); //This should succeed. - reset_file( "tmp1.txt" ); //Creates empty file. - try - { - copy_data( "tmp1.txt", "tmp2.txt" ); //This should fail, tmp1.txt is empty. - } - catch( - read_error & x ) - { - std::cout << "\nCaught 'read_error' exception.\n"; - dump_all_info(x); - } + reset_file( "tmp1.txt" ); //Creates empty file. + try + { + copy_data( "tmp1.txt", "tmp2.txt" ); //This should fail, tmp1.txt is empty. + } + catch( + read_error & x ) + { + std::cout << "\nCaught 'read_error' exception.\n"; + dump_all_info(x); + } - remove( "tmp1.txt" ); - remove( "tmp2.txt" ); - try - { - copy_data( "tmp1.txt", "tmp2.txt" ); //This should fail, tmp1.txt does not exist. - } - catch( - open_error & x ) - { - std::cout << "\nCaught 'open_error' exception.\n"; - dump_all_info(x); - } - } - catch( - boost::exception & x ) - { - std::cout << "\nCaught unexpected boost::exception!\n"; - dump_all_info(x); - } - } + remove( "tmp1.txt" ); + remove( "tmp2.txt" ); + try + { + copy_data( "tmp1.txt", "tmp2.txt" ); //This should fail, tmp1.txt does not exist. + } + catch( + open_error & x ) + { + std::cout << "\nCaught 'open_error' exception.\n"; + dump_all_info(x); + } + } + catch( + boost::exception & x ) + { + std::cout << "\nCaught unexpected boost::exception!\n"; + dump_all_info(x); + } + } diff --git a/example/logging.cpp b/example/logging.cpp index 7dde008..dd81922 100644 --- a/example/logging.cpp +++ b/example/logging.cpp @@ -12,14 +12,14 @@ void f(); //throws unknown types that derive from boost::exception. void g() - { + { try - { + { f(); - } + } catch( - boost::exception & e ) - { + boost::exception & e ) + { std::cerr << e.what(); - } - } + } + } diff --git a/include/boost/exception/cloning.hpp b/include/boost/exception/cloning.hpp index d45cc52..4025762 100644 --- a/include/boost/exception/cloning.hpp +++ b/include/boost/exception/cloning.hpp @@ -13,47 +13,47 @@ namespace boost - { - class - unknown_exception: - public exception, - public std::exception - { - public: + { + class + unknown_exception: + public exception, + public std::exception + { + public: - explicit - unknown_exception() - { - } + explicit + unknown_exception() + { + } - explicit - unknown_exception( boost::exception const & x ): - boost::exception(x) - { - } - }; + explicit + unknown_exception( boost::exception const & x ): + boost::exception(x) + { + } + }; - typedef intrusive_ptr exception_ptr; + typedef intrusive_ptr exception_ptr; - template - exception_ptr - clone_exception( T const & e ) - { - if( boost::exception_detail::cloning_base const * cb = dynamic_cast(&e) ) - if( exception_detail::clone_base const * c = cb->clone() ) - return exception_ptr(c); - if( boost::exception const * be = dynamic_cast(&e) ) - return exception_ptr(exception_detail::make_clone(unknown_exception(*be))); - else - return exception_ptr(exception_detail::make_clone(unknown_exception())); - } + template + exception_ptr + clone_exception( T const & e ) + { + if( boost::exception_detail::cloning_base const * cb = dynamic_cast(&e) ) + if( exception_detail::clone_base const * c = cb->clone() ) + return exception_ptr(c); + if( boost::exception const * be = dynamic_cast(&e) ) + return exception_ptr(exception_detail::make_clone(unknown_exception(*be))); + else + return exception_ptr(exception_detail::make_clone(unknown_exception())); + } - inline - void - rethrow_exception( exception_ptr const & p ) - { - p->rethrow(); - } - } + inline + void + rethrow_exception( exception_ptr const & p ) + { + p->rethrow(); + } + } #endif diff --git a/include/boost/exception/detail/cloning_base.hpp b/include/boost/exception/detail/cloning_base.hpp index 1bc0412..a7e4db0 100644 --- a/include/boost/exception/detail/cloning_base.hpp +++ b/include/boost/exception/detail/cloning_base.hpp @@ -8,20 +8,20 @@ namespace boost - { - namespace - exception_detail - { - class clone_base; + { + namespace + exception_detail + { + class clone_base; - class - cloning_base - { - public: + class + cloning_base + { + public: - virtual clone_base const * clone() const = 0; - }; - } - } + virtual clone_base const * clone() const = 0; + }; + } + } #endif diff --git a/include/boost/exception/detail/counted_base.hpp b/include/boost/exception/detail/counted_base.hpp index c842cbc..4df0589 100644 --- a/include/boost/exception/detail/counted_base.hpp +++ b/include/boost/exception/detail/counted_base.hpp @@ -8,31 +8,31 @@ namespace boost - { - namespace - exception_detail - { - class - counted_base - { - friend - void - intrusive_ptr_add_ref( counted_base const * c ) - { - c->add_ref(); - } + { + namespace + exception_detail + { + class + counted_base + { + friend + void + intrusive_ptr_add_ref( counted_base const * c ) + { + c->add_ref(); + } - friend - void - intrusive_ptr_release( counted_base const * c ) - { - c->release(); - } + friend + void + intrusive_ptr_release( counted_base const * c ) + { + c->release(); + } - virtual void add_ref() const=0; - virtual void release() const=0; - }; - } - } + virtual void add_ref() const=0; + virtual void release() const=0; + }; + } + } #endif diff --git a/include/boost/exception/enable_error_info.hpp b/include/boost/exception/enable_error_info.hpp index 1deee95..2214ad5 100644 --- a/include/boost/exception/enable_error_info.hpp +++ b/include/boost/exception/enable_error_info.hpp @@ -10,60 +10,60 @@ namespace boost - { - namespace - exception_detail - { - template - struct - error_info_injector: - public T, - public exception - { - explicit - error_info_injector( T const & x ): - T(x) - { - } - }; + { + namespace + exception_detail + { + template + struct + error_info_injector: + public T, + public exception + { + explicit + error_info_injector( T const & x ): + T(x) + { + } + }; - struct large_size { char c[256]; }; - large_size dispatch( exception * ); + struct large_size { char c[256]; }; + large_size dispatch( exception * ); - struct small_size { }; - small_size dispatch( void * ); + struct small_size { }; + small_size dispatch( void * ); - template - struct enable_error_info_helper; + template + struct enable_error_info_helper; - template - struct - enable_error_info_helper - { - typedef T type; - }; + template + struct + enable_error_info_helper + { + typedef T type; + }; - template - struct - enable_error_info_helper - { - typedef error_info_injector type; - }; + template + struct + enable_error_info_helper + { + typedef error_info_injector type; + }; - template - struct - enable_error_info_return_type - { - typedef typename enable_error_info_helper::type type; - }; - } + template + struct + enable_error_info_return_type + { + typedef typename enable_error_info_helper::type type; + }; + } - template - typename exception_detail::enable_error_info_return_type::type - enable_error_info( T const & x ) - { - return typename exception_detail::enable_error_info_return_type::type(x); - } - } + template + typename exception_detail::enable_error_info_return_type::type + enable_error_info( T const & x ) + { + return typename exception_detail::enable_error_info_return_type::type(x); + } + } #endif diff --git a/include/boost/exception/enable_exception_cloning.hpp b/include/boost/exception/enable_exception_cloning.hpp index 2532d06..2e732f5 100644 --- a/include/boost/exception/enable_exception_cloning.hpp +++ b/include/boost/exception/enable_exception_cloning.hpp @@ -14,135 +14,135 @@ namespace boost - { - namespace - exception_detail - { - class - clone_base: - public counted_base - { - public: + { + namespace + exception_detail + { + class + clone_base: + public counted_base + { + public: - virtual void rethrow() const=0; - }; + virtual void rethrow() const=0; + }; - struct - bad_alloc_impl: - public clone_base, - public std::bad_alloc - { - void - add_ref() const - { - } + struct + bad_alloc_impl: + public clone_base, + public std::bad_alloc + { + void + add_ref() const + { + } - void - release() const - { - } + void + release() const + { + } - void - rethrow() const - { - throw *this; - } - }; + void + rethrow() const + { + throw *this; + } + }; - template - clone_base * make_clone( T const & ); + template + clone_base * make_clone( T const & ); - template - class - clone_impl: - public T, - public cloning_base - { - public: + template + class + clone_impl: + public T, + public cloning_base + { + public: - explicit - clone_impl( T const & x ): - T(x) - { - } + explicit + clone_impl( T const & x ): + T(x) + { + } - private: + private: - clone_base const * - clone() const - { - return make_clone(*this); - } - }; + clone_base const * + clone() const + { + return make_clone(*this); + } + }; - template - class - exception_clone: - public T, - public clone_base - { - public: + template + class + exception_clone: + public T, + public clone_base + { + public: - explicit - exception_clone( T const & x ): - T(x), - count_(0) - { - } + explicit + exception_clone( T const & x ): + T(x), + count_(0) + { + } - private: + private: - detail::atomic_count mutable count_; + detail::atomic_count mutable count_; - void - add_ref() const - { - ++count_; - } + void + add_ref() const + { + ++count_; + } - void - release() const - { - if( !--count_ ) - delete this; - } + void + release() const + { + if( !--count_ ) + delete this; + } - void - rethrow() const - { - throw clone_impl(*this); - } - }; + void + rethrow() const + { + throw clone_impl(*this); + } + }; - template - clone_base * - make_clone( T const & x ) - { - try - { - return new exception_clone(x); - } - catch( - std::bad_alloc & ) - { - static bad_alloc_impl bad_alloc; - return &bad_alloc; - } - catch( - ... ) - { - BOOST_ASSERT(0); - return 0; - } - } - } + template + clone_base * + make_clone( T const & x ) + { + try + { + return new exception_clone(x); + } + catch( + std::bad_alloc & ) + { + static bad_alloc_impl bad_alloc; + return &bad_alloc; + } + catch( + ... ) + { + BOOST_ASSERT(0); + return 0; + } + } + } - template - exception_detail::clone_impl - enable_exception_cloning( T const & x ) - { - return exception_detail::clone_impl(x); - } - } + template + exception_detail::clone_impl + enable_exception_cloning( T const & x ) + { + return exception_detail::clone_impl(x); + } + } #endif diff --git a/include/boost/exception/error_info.hpp b/include/boost/exception/error_info.hpp index 816942f..23f6f30 100644 --- a/include/boost/exception/error_info.hpp +++ b/include/boost/exception/error_info.hpp @@ -8,9 +8,9 @@ namespace boost - { - template - class error_info; - } + { + template + class error_info; + } #endif diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp index ec1bf1b..2180d50 100644 --- a/include/boost/exception/exception.hpp +++ b/include/boost/exception/exception.hpp @@ -12,79 +12,79 @@ namespace boost - { - template - class shared_ptr; + { + template + class shared_ptr; - namespace - exception_detail - { - class error_info_base; + namespace + exception_detail + { + class error_info_base; - struct - error_info_container: - public exception_detail::counted_base - { - virtual char const * what( std::type_info const & ) const = 0; - virtual shared_ptr get( std::type_info const & ) const = 0; - virtual void set( shared_ptr const & ) = 0; - }; - } + struct + error_info_container: + public exception_detail::counted_base + { + virtual char const * what( std::type_info const & ) const = 0; + virtual shared_ptr get( std::type_info const & ) const = 0; + virtual void set( shared_ptr const & ) = 0; + }; + } - template - class error_info; + template + class error_info; - template - E const & operator<<( E const &, error_info const & ); + template + E const & operator<<( E const &, error_info const & ); - template - shared_ptr get_error_info( E const & ); + template + shared_ptr get_error_info( E const & ); - class - exception - { - public: + class + exception + { + public: - virtual ~exception() throw()=0; - virtual char const * what() const throw(); + virtual ~exception() throw()=0; + virtual char const * what() const throw(); - private: + private: - shared_ptr get( std::type_info const & ) const; - void set( shared_ptr const & ) const; + shared_ptr get( std::type_info const & ) const; + void set( shared_ptr const & ) const; - template - friend E const & operator<<( E const &, error_info const & ); + template + friend E const & operator<<( E const &, error_info const & ); - template - friend shared_ptr get_error_info( E const & ); + template + friend shared_ptr get_error_info( E const & ); - intrusive_ptr mutable data_; - }; + intrusive_ptr mutable data_; + }; - inline - exception:: - ~exception() throw() - { - } + inline + exception:: + ~exception() throw() + { + } - inline - char const * - exception:: - what() const throw() - { - if( data_ ) - try - { - char const * w = data_->what(typeid(*this)); - BOOST_ASSERT(0!=w); - return w; - } - catch(...) - { - } - return typeid(*this).name(); - } - } + inline + char const * + exception:: + what() const throw() + { + if( data_ ) + try + { + char const * w = data_->what(typeid(*this)); + BOOST_ASSERT(0!=w); + return w; + } + catch(...) + { + } + return typeid(*this).name(); + } + } #endif diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp index a67bb9b..2f6e936 100644 --- a/include/boost/exception/info.hpp +++ b/include/boost/exception/info.hpp @@ -15,219 +15,219 @@ #include #define BOOST_ERROR_INFO\ - ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ - ::boost::throw_file(__FILE__) <<\ - ::boost::throw_line((int)__LINE__) + ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ + ::boost::throw_file(__FILE__) <<\ + ::boost::throw_line((int)__LINE__) namespace boost - { - typedef error_info throw_function; - typedef error_info throw_file; - typedef error_info throw_line; + { + typedef error_info throw_function; + typedef error_info throw_file; + typedef error_info throw_line; - namespace - exception_detail - { - class - error_info_base - { - public: + namespace + exception_detail + { + class + error_info_base + { + public: - virtual std::type_info const & tag_typeid() const = 0; - virtual std::string value_as_string() const = 0; - }; - } + virtual std::type_info const & tag_typeid() const = 0; + virtual std::string value_as_string() const = 0; + }; + } - template - class - error_info: - public exception_detail::error_info_base - { - public: + template + class + error_info: + public exception_detail::error_info_base + { + public: - typedef T value_type; + typedef T value_type; - error_info( value_type const & value ): - value_(value) - { - } + error_info( value_type const & value ): + value_(value) + { + } - value_type const & - value() const - { - return value_; - } + value_type const & + value() const + { + return value_; + } - private: + private: - std::type_info const & - tag_typeid() const - { - return typeid(type); - } + std::type_info const & + tag_typeid() const + { + return typeid(type); + } - std::string - value_as_string() const - { - return to_string_stub(value_); - } + std::string + value_as_string() const + { + return to_string_stub(value_); + } - value_type const value_; - }; + value_type const value_; + }; - template - struct - error_info_type - { - typedef typename ErrorInfo::value_type value_type; - }; + template + struct + error_info_type + { + typedef typename ErrorInfo::value_type value_type; + }; - template - E const & - operator<<( E const & x, error_info const & v ) - { - shared_ptr< error_info > p( new error_info(v) ); - x.set(p); - return x; - } + template + E const & + operator<<( E const & x, error_info const & v ) + { + shared_ptr< error_info > p( new error_info(v) ); + x.set(p); + return x; + } - template - shared_ptr - get_error_info( E const & some_exception ) - { - if( exception const * x = dynamic_cast(&some_exception) ) - if( shared_ptr eib = x->get(typeid(ErrorInfo)) ) - { - BOOST_ASSERT( 0!=dynamic_cast(eib.get()) ); - ErrorInfo const * w = static_cast(eib.get()); - return shared_ptr(eib,&w->value()); - } - return shared_ptr(); - } + template + shared_ptr + get_error_info( E const & some_exception ) + { + if( exception const * x = dynamic_cast(&some_exception) ) + if( shared_ptr eib = x->get(typeid(ErrorInfo)) ) + { + BOOST_ASSERT( 0!=dynamic_cast(eib.get()) ); + ErrorInfo const * w = static_cast(eib.get()); + return shared_ptr(eib,&w->value()); + } + return shared_ptr(); + } - namespace - exception_detail - { - class - error_info_container_impl: - public error_info_container - { - public: + namespace + exception_detail + { + class + error_info_container_impl: + public error_info_container + { + public: - error_info_container_impl(): - count_(0) - { - } + error_info_container_impl(): + count_(0) + { + } - ~error_info_container_impl() throw() - { - } + ~error_info_container_impl() throw() + { + } - shared_ptr - get( std::type_info const & ti ) const - { - error_info_map::const_iterator i=info_.find(typeinfo(ti)); - if( info_.end()!=i ) - { - shared_ptr const & p = i->second; - BOOST_ASSERT( typeid(*p)==ti ); - return p; - } - return shared_ptr(); - } + shared_ptr + get( std::type_info const & ti ) const + { + error_info_map::const_iterator i=info_.find(typeinfo(ti)); + if( info_.end()!=i ) + { + shared_ptr const & p = i->second; + BOOST_ASSERT( typeid(*p)==ti ); + return p; + } + return shared_ptr(); + } - void - set( shared_ptr const & x ) - { - BOOST_ASSERT(x); - info_[typeinfo(typeid(*x))] = x; - what_.clear(); - } + void + set( shared_ptr const & x ) + { + BOOST_ASSERT(x); + info_[typeinfo(typeid(*x))] = x; + what_.clear(); + } - char const * - what( std::type_info const & exception_type ) const - { - if( what_.empty() ) - { - std::string tmp(exception_type.name()); - tmp += '\n'; - for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i ) - { - shared_ptr const & x = i->second; - tmp += '['; - tmp += x->tag_typeid().name(); - tmp += "] = "; - tmp += x->value_as_string(); - tmp += '\n'; - } - what_.swap(tmp); - } - return what_.c_str(); - } + char const * + what( std::type_info const & exception_type ) const + { + if( what_.empty() ) + { + std::string tmp(exception_type.name()); + tmp += '\n'; + for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i ) + { + shared_ptr const & x = i->second; + tmp += '['; + tmp += x->tag_typeid().name(); + tmp += "] = "; + tmp += x->value_as_string(); + tmp += '\n'; + } + what_.swap(tmp); + } + return what_.c_str(); + } - private: + private: - friend class exception; + friend class exception; - struct - typeinfo - { - std::type_info const * type; + struct + typeinfo + { + std::type_info const * type; - explicit - typeinfo( std::type_info const & t ): - type(&t) - { - } + explicit + typeinfo( std::type_info const & t ): + type(&t) + { + } - bool - operator<( typeinfo const & b ) const - { - return 0!=(type->before(*b.type)); - } - }; + bool + operator<( typeinfo const & b ) const + { + return 0!=(type->before(*b.type)); + } + }; - typedef std::map< typeinfo, shared_ptr > error_info_map; - error_info_map info_; - std::string mutable what_; - int mutable count_; + typedef std::map< typeinfo, shared_ptr > error_info_map; + error_info_map info_; + std::string mutable what_; + int mutable count_; - void - add_ref() const - { - ++count_; - } + void + add_ref() const + { + ++count_; + } - void - release() const - { - if( !--count_ ) - delete this; - } - }; - } + void + release() const + { + if( !--count_ ) + delete this; + } + }; + } - inline - void - exception:: - set( shared_ptr const & x ) const - { - if( !data_ ) - data_ = intrusive_ptr(new exception_detail::error_info_container_impl); - data_->set(x); - } + inline + void + exception:: + set( shared_ptr const & x ) const + { + if( !data_ ) + data_ = intrusive_ptr(new exception_detail::error_info_container_impl); + data_->set(x); + } - inline - shared_ptr - exception:: - get( std::type_info const & ti ) const - { - if( data_ ) - return data_->get(ti); - else - return shared_ptr(); - } - } + inline + shared_ptr + exception:: + get( std::type_info const & ti ) const + { + if( data_ ) + return data_->get(ti); + else + return shared_ptr(); + } + } #endif diff --git a/include/boost/exception/info_tuple.hpp b/include/boost/exception/info_tuple.hpp index becd210..43a9a76 100644 --- a/include/boost/exception/info_tuple.hpp +++ b/include/boost/exception/info_tuple.hpp @@ -11,54 +11,54 @@ namespace boost - { - template < - class E, - class Tag1,class T1, - class Tag2,class T2 > - E const & - operator<<( - E const & x, - tuple< - error_info, - error_info > const & v ) - { - return x << v.template get<0>() << v.template get<1>(); - } + { + template < + class E, + class Tag1,class T1, + class Tag2,class T2 > + E const & + operator<<( + E const & x, + tuple< + error_info, + error_info > const & v ) + { + return x << v.template get<0>() << v.template get<1>(); + } - template < - class E, - class Tag1,class T1, - class Tag2,class T2, - class Tag3,class T3 > - E const & - operator<<( - E const & x, - tuple< - error_info, - error_info, - error_info > const & v ) - { - return x << v.template get<0>() << v.template get<1>() << v.template get<2>(); - } + template < + class E, + class Tag1,class T1, + class Tag2,class T2, + class Tag3,class T3 > + E const & + operator<<( + E const & x, + tuple< + error_info, + error_info, + error_info > const & v ) + { + return x << v.template get<0>() << v.template get<1>() << v.template get<2>(); + } - template < - class E, - class Tag1,class T1, - class Tag2,class T2, - class Tag3,class T3, - class Tag4,class T4 > - E const & - operator<<( - E const & x, - tuple< - error_info, - error_info, - error_info, - error_info > const & v ) - { - return x << v.template get<0>() << v.template get<1>() << v.template get<2>() << v.template get<3>(); - } - } + template < + class E, + class Tag1,class T1, + class Tag2,class T2, + class Tag3,class T3, + class Tag4,class T4 > + E const & + operator<<( + E const & x, + tuple< + error_info, + error_info, + error_info, + error_info > const & v ) + { + return x << v.template get<0>() << v.template get<1>() << v.template get<2>() << v.template get<3>(); + } + } #endif diff --git a/include/boost/exception/to_string.hpp b/include/boost/exception/to_string.hpp index c52e350..871e6f4 100644 --- a/include/boost/exception/to_string.hpp +++ b/include/boost/exception/to_string.hpp @@ -10,18 +10,18 @@ namespace boost - { - namespace - { - template - std::string - to_string( T const & x ) - { - std::ostringstream out; - out << x; - return out.str(); - } - } - } + { + namespace + { + template + std::string + to_string( T const & x ) + { + std::ostringstream out; + out << x; + return out.str(); + } + } + } #endif diff --git a/include/boost/exception/to_string_stub.hpp b/include/boost/exception/to_string_stub.hpp index 4b6492b..ffefb5e 100644 --- a/include/boost/exception/to_string_stub.hpp +++ b/include/boost/exception/to_string_stub.hpp @@ -12,138 +12,135 @@ namespace boost - { - namespace - exception_detail - { - template - struct shift_left_dispatcher; + { + namespace + exception_detail + { + template + struct shift_left_dispatcher; - template <> - struct - shift_left_dispatcher - { - template - static - void - convert( std::basic_ostream & out, T const & x, Stub ) - { - out << x; - } - }; + template <> + struct + shift_left_dispatcher + { + template + static + void + convert( std::basic_ostream & out, T const & x, Stub ) + { + out << x; + } + }; - template <> - struct - shift_left_dispatcher - { - template - static - void - convert( std::basic_ostream & out, T const & x, Stub s ) - { - out << s(x); - } - }; + template <> + struct + shift_left_dispatcher + { + template + static + void + convert( std::basic_ostream & out, T const & x, Stub s ) + { + out << s(x); + } + }; - namespace - shift_left_dispatch - { - template - char operator<<( std::basic_ostream &, T ); + namespace + shift_left_dispatch + { + template + char operator<<( std::basic_ostream &, T ); - template - void - dispatch( std::basic_ostream & out, T const & x, Stub s ) - { - shift_left_dispatcher<1!=sizeof(out<::convert(out,x,s); - } - } - } + template + void + dispatch( std::basic_ostream & out, T const & x, Stub s ) + { + shift_left_dispatcher<1!=sizeof(out<::convert(out,x,s); + } + } + } - namespace - exception_detail - { - template - struct to_string_dispatcher; + namespace + exception_detail + { + template + struct + to_string_dispatcher + { + template + static + std::string + convert( T const & x, Stub ) + { + return to_string(x); + } + }; - template <> - struct - to_string_dispatcher - { - template - static - std::string - convert( T const & x, Stub ) - { - return to_string(x); - } - }; + template <> + struct + to_string_dispatcher + { + template + static + std::string + convert( T const & x, Stub s ) + { + std::ostringstream out; + shift_left_dispatch::dispatch(out,x,s); + return out.str(); + } + }; - template <> - struct - to_string_dispatcher - { - template - static - std::string - convert( T const & x, Stub s ) - { - std::ostringstream out; - shift_left_dispatch::dispatch(out,x,s); - return out.str(); - } - }; + namespace + to_string_dispatch + { + template + char to_string( T ); - namespace - to_string_dispatch - { - template - char to_string( T ); + template + std::string + dispatch( T const & x, Stub s ) + { + return to_string_dispatcher<1!=sizeof(to_string(x))>::convert(x,s); + } + } - template - std::string - dispatch( T const & x, Stub s ) - { - return to_string_dispatcher<1!=sizeof(to_string(x))>::convert(x,s); - } - } + template + std::string + string_stub_dump( T const & x ) + { + std::ostringstream s; + s << "[ type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: "; + size_t n=sizeof(T)>16?16:sizeof(T); + s.fill('0'); + s.width(2); + for( unsigned char const * b=reinterpret_cast(&x),* e=b+n; b!=e; ++b ) + s << std::setw(2) << std::hex << (unsigned int)*b << " "; + s << "]"; + return s.str(); + } + } - template - std::string - string_stub_dump( T const & x ) - { - std::ostringstream s; - s << "[ type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: "; - size_t n=sizeof(T)>16?16:sizeof(T); - s.fill('0'); - s.width(2); - for( unsigned char const * b=reinterpret_cast(&x),* e=b+n; b!=e; ++b ) - s << std::setw(2) << std::hex << (unsigned int)*b << " "; - s << "]"; - return s.str(); - } - } + template + std::string + to_string_stub( T const & x ) + { + return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump); + } - template - std::string - to_string_stub( T const & x ) - { - return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump); - } + template + std::string + to_string_stub( T const & x, Stub s ) + { + return exception_detail::to_string_dispatch::dispatch(x,s); + } - template - std::string - to_string_stub( T const & x, Stub s ) - { - return exception_detail::to_string_dispatch::dispatch(x,s); - } - - template - std::string - to_string( std::pair const & x ) - { - return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')'; - } - } + template + std::string + to_string( std::pair const & x ) + { + return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')'; + } + } #endif diff --git a/test/boost_error_info_test.cpp b/test/boost_error_info_test.cpp index 86be899..d919eb7 100644 --- a/test/boost_error_info_test.cpp +++ b/test/boost_error_info_test.cpp @@ -9,32 +9,32 @@ namespace test - { - class my_exception: public boost::exception { }; + { + class my_exception: public boost::exception { }; - typedef boost::error_info my_info; + typedef boost::error_info my_info; - void - test_boost_error_info() - { - try - { - throw my_exception() << BOOST_ERROR_INFO << my_info(1); - } - catch( - my_exception & x ) - { - BOOST_TEST(1==*boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)); - BOOST_TEST(boost::get_error_info(x)); - } - } - } + void + test_boost_error_info() + { + try + { + throw my_exception() << BOOST_ERROR_INFO << my_info(1); + } + catch( + my_exception & x ) + { + BOOST_TEST(1==*boost::get_error_info(x)); + BOOST_TEST(boost::get_error_info(x)); + BOOST_TEST(boost::get_error_info(x)); + BOOST_TEST(boost::get_error_info(x)); + } + } + } int main() - { - test::test_boost_error_info(); - return boost::report_errors(); - } + { + test::test_boost_error_info(); + return boost::report_errors(); + } diff --git a/test/cloning_test.cpp b/test/cloning_test.cpp index 5c480fc..9052cc5 100644 --- a/test/cloning_test.cpp +++ b/test/cloning_test.cpp @@ -8,35 +8,35 @@ struct test_exception: - std::exception - { - }; + std::exception + { + }; int main() - { - try - { - throw boost::enable_exception_cloning(test_exception()); - } - catch( - std::exception & x ) - { - boost::exception_ptr p = boost::clone_exception(x); - try - { - rethrow_exception(p); - BOOST_TEST(false); - } - catch( - test_exception & ) - { - } - catch( - ... ) - { - BOOST_TEST(false); - } - } - return boost::report_errors(); - } + { + try + { + throw boost::enable_exception_cloning(test_exception()); + } + catch( + std::exception & x ) + { + boost::exception_ptr p = boost::clone_exception(x); + try + { + rethrow_exception(p); + BOOST_TEST(false); + } + catch( + test_exception & ) + { + } + catch( + ... ) + { + BOOST_TEST(false); + } + } + return boost::report_errors(); + } diff --git a/test/enable_error_info_test.cpp b/test/enable_error_info_test.cpp index d107597..d9b7076 100644 --- a/test/enable_error_info_test.cpp +++ b/test/enable_error_info_test.cpp @@ -8,42 +8,42 @@ #include namespace - { - typedef boost::error_info test_int; + { + typedef boost::error_info test_int; - void - throw_wrapper() - { - try - { - boost::exception_test::throw_length_error(); - } - catch( - boost::exception & x ) - { - x << test_int(42); - throw; - } - } - } + void + throw_wrapper() + { + try + { + boost::exception_test::throw_length_error(); + } + catch( + boost::exception & x ) + { + x << test_int(42); + throw; + } + } + } int main() - { - try - { - throw_wrapper(); - BOOST_TEST(false); - } - catch( - std::exception & x ) - { - BOOST_TEST( 42==*boost::get_error_info(x) ); - } - catch( - ... ) - { - BOOST_TEST(false); - } - return boost::report_errors(); - } + { + try + { + throw_wrapper(); + BOOST_TEST(false); + } + catch( + std::exception & x ) + { + BOOST_TEST( 42==*boost::get_error_info(x) ); + } + catch( + ... ) + { + BOOST_TEST(false); + } + return boost::report_errors(); + } diff --git a/test/errno_test.cpp b/test/errno_test.cpp index 78a02f0..7280068 100644 --- a/test/errno_test.cpp +++ b/test/errno_test.cpp @@ -11,23 +11,23 @@ typedef boost::error_info info_errno; class my_exception: - public boost::exception - { - }; + public boost::exception + { + }; int main() - { - try - { - errno=1; - throw my_exception() << info_errno(errno); - BOOST_TEST(false); - } - catch( - my_exception & x ) - { - BOOST_TEST(1==*boost::get_error_info(x)); - } - return boost::report_errors(); - } + { + try + { + errno=1; + throw my_exception() << info_errno(errno); + BOOST_TEST(false); + } + catch( + my_exception & x ) + { + BOOST_TEST(1==*boost::get_error_info(x)); + } + return boost::report_errors(); + } diff --git a/test/error_info_test.cpp b/test/error_info_test.cpp index 54c8f68..988975d 100644 --- a/test/error_info_test.cpp +++ b/test/error_info_test.cpp @@ -18,200 +18,200 @@ typedef boost::error_info test_6; struct test_exception: - public boost::exception - { - }; + public boost::exception + { + }; struct throws_on_copy - { - throws_on_copy() - { - } + { + throws_on_copy() + { + } - throws_on_copy( throws_on_copy const & ) - { - throw test_exception(); - } - }; + throws_on_copy( throws_on_copy const & ) + { + throw test_exception(); + } + }; void basic_test() - { - test_exception x; - x << test_1(1) << test_2(2u) << test_3(3.14159f); - BOOST_TEST(*boost::get_error_info(x)==1); - BOOST_TEST(*boost::get_error_info(x)==2u); - BOOST_TEST(*boost::get_error_info(x)==3.14159f); - BOOST_TEST(!boost::get_error_info(x)); - } + { + test_exception x; + x << test_1(1) << test_2(2u) << test_3(3.14159f); + BOOST_TEST(*boost::get_error_info(x)==1); + BOOST_TEST(*boost::get_error_info(x)==2u); + BOOST_TEST(*boost::get_error_info(x)==3.14159f); + BOOST_TEST(!boost::get_error_info(x)); + } void exception_safety_test() - { - test_exception x; - try - { - x << test_4(throws_on_copy()); - BOOST_TEST(false); - } - catch( - test_exception & ) - { - } - BOOST_TEST(!boost::get_error_info(x)); - } + { + test_exception x; + try + { + x << test_4(throws_on_copy()); + BOOST_TEST(false); + } + catch( + test_exception & ) + { + } + BOOST_TEST(!boost::get_error_info(x)); + } void throw_empty() - { - throw test_exception(); - } + { + throw test_exception(); + } void throw_test_1( char const * value ) - { - throw test_exception() << test_5(std::string(value)); - } + { + throw test_exception() << test_5(std::string(value)); + } void throw_test_2() - { - throw test_exception() << test_6(non_printable()); - } + { + throw test_exception() << test_6(non_printable()); + } void throw_catch_add_file_name( char const * name ) - { - try - { - throw_empty(); - BOOST_TEST(false); - } - catch( - boost::exception & x ) - { - x << test_5(std::string(name)); - throw; - } - } + { + try + { + throw_empty(); + BOOST_TEST(false); + } + catch( + boost::exception & x ) + { + x << test_5(std::string(name)); + throw; + } + } void test_empty() - { - try - { - throw_empty(); - BOOST_TEST(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST( dynamic_cast(&x) ); - BOOST_TEST( !boost::get_error_info(x) ); - } + { + try + { + throw_empty(); + BOOST_TEST(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST( dynamic_cast(&x) ); + BOOST_TEST( !boost::get_error_info(x) ); + } - try - { - throw_empty(); - BOOST_TEST(false); - } - catch( - test_exception & x ) - { - BOOST_TEST( dynamic_cast(&x) ); - } - } + try + { + throw_empty(); + BOOST_TEST(false); + } + catch( + test_exception & x ) + { + BOOST_TEST( dynamic_cast(&x) ); + } + } void test_basic_throw_catch() - { - try - { - throw_test_1("test"); - BOOST_ASSERT(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(*boost::get_error_info(x)==std::string("test")); - } - try - { - throw_test_2(); - BOOST_ASSERT(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(boost::get_error_info(x)); - } - } + { + try + { + throw_test_1("test"); + BOOST_ASSERT(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(*boost::get_error_info(x)==std::string("test")); + } + try + { + throw_test_2(); + BOOST_ASSERT(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(boost::get_error_info(x)); + } + } void test_catch_add_info() - { - try - { - throw_catch_add_file_name("test"); - BOOST_TEST(false); - } - catch( - boost::exception & x ) - { - BOOST_TEST(*boost::get_error_info(x)==std::string("test")); - } - } + { + try + { + throw_catch_add_file_name("test"); + BOOST_TEST(false); + } + catch( + boost::exception & x ) + { + BOOST_TEST(*boost::get_error_info(x)==std::string("test")); + } + } void test_add_tuple() - { - typedef boost::tuple test_12; - typedef boost::tuple test_123; - typedef boost::tuple test_1235; - try - { - throw test_exception() << test_12(42,42u); - } - catch( - test_exception & x ) - { - BOOST_TEST( *boost::get_error_info(x)==42 ); - BOOST_TEST( *boost::get_error_info(x)==42u ); - } - try - { - throw test_exception() << test_123(42,42u,42.0f); - } - catch( - test_exception & x ) - { - BOOST_TEST( *boost::get_error_info(x)==42 ); - BOOST_TEST( *boost::get_error_info(x)==42u ); - BOOST_TEST( *boost::get_error_info(x)==42.0f ); - } - try - { - throw test_exception() << test_1235(42,42u,42.0f,std::string("42")); - } - catch( - test_exception & x ) - { - BOOST_TEST( *boost::get_error_info(x)==42 ); - BOOST_TEST( *boost::get_error_info(x)==42u ); - BOOST_TEST( *boost::get_error_info(x)==42.0f ); - BOOST_TEST( *boost::get_error_info(x)=="42" ); - } - } + { + typedef boost::tuple test_12; + typedef boost::tuple test_123; + typedef boost::tuple test_1235; + try + { + throw test_exception() << test_12(42,42u); + } + catch( + test_exception & x ) + { + BOOST_TEST( *boost::get_error_info(x)==42 ); + BOOST_TEST( *boost::get_error_info(x)==42u ); + } + try + { + throw test_exception() << test_123(42,42u,42.0f); + } + catch( + test_exception & x ) + { + BOOST_TEST( *boost::get_error_info(x)==42 ); + BOOST_TEST( *boost::get_error_info(x)==42u ); + BOOST_TEST( *boost::get_error_info(x)==42.0f ); + } + try + { + throw test_exception() << test_1235(42,42u,42.0f,std::string("42")); + } + catch( + test_exception & x ) + { + BOOST_TEST( *boost::get_error_info(x)==42 ); + BOOST_TEST( *boost::get_error_info(x)==42u ); + BOOST_TEST( *boost::get_error_info(x)==42.0f ); + BOOST_TEST( *boost::get_error_info(x)=="42" ); + } + } int main() - { - basic_test(); - exception_safety_test(); - test_empty(); - test_basic_throw_catch(); - test_catch_add_info(); - test_add_tuple(); - return boost::report_errors(); - } + { + basic_test(); + exception_safety_test(); + test_empty(); + test_basic_throw_catch(); + test_catch_add_info(); + test_add_tuple(); + return boost::report_errors(); + } diff --git a/test/exception_fail.cpp b/test/exception_fail.cpp index d39b27a..0edbf7e 100644 --- a/test/exception_fail.cpp +++ b/test/exception_fail.cpp @@ -7,6 +7,6 @@ void tester( boost::exception & x ) - { - throw x; //must not compile. - } + { + throw x; //must not compile. + } diff --git a/test/exception_test.cpp b/test/exception_test.cpp index 39ace16..7cadc5d 100644 --- a/test/exception_test.cpp +++ b/test/exception_test.cpp @@ -8,28 +8,28 @@ class test_exception: - public boost::exception - { - }; + public boost::exception + { + }; void test_throw() - { - throw test_exception(); - } + { + throw test_exception(); + } int main() - { - try - { - test_throw(); - BOOST_TEST(false); - } - catch( - test_exception & ) - { - BOOST_TEST(true); - } - return boost::report_errors(); - } + { + try + { + test_throw(); + BOOST_TEST(false); + } + catch( + test_exception & ) + { + BOOST_TEST(true); + } + return boost::report_errors(); + } diff --git a/test/helper1.cpp b/test/helper1.cpp index 1446bd2..3f2d214 100644 --- a/test/helper1.cpp +++ b/test/helper1.cpp @@ -5,17 +5,18 @@ #include #include +#include namespace boost - { - namespace - exception_test - { - void - throw_length_error() - { - throw enable_error_info( std::length_error("my length error") ); - } - } - } + { + namespace + exception_test + { + void + throw_length_error() + { + throw enable_error_info( std::length_error("my length error") ); + } + } + } diff --git a/test/helper1.hpp b/test/helper1.hpp index 531983b..65570dc 100644 --- a/test/helper1.hpp +++ b/test/helper1.hpp @@ -8,12 +8,12 @@ namespace boost - { - namespace - exception_test - { - void throw_length_error(); - } - } + { + namespace + exception_test + { + void throw_length_error(); + } + } #endif diff --git a/test/helper2.cpp b/test/helper2.cpp index 42b5721..7fce317 100644 --- a/test/helper2.cpp +++ b/test/helper2.cpp @@ -8,46 +8,46 @@ namespace boost - { - namespace - exception_test - { - inline - some_boost_exception:: - some_boost_exception( int x ): - x_(x) - { - } + { + namespace + exception_test + { + inline + some_boost_exception:: + some_boost_exception( int x ): + x_(x) + { + } - some_boost_exception:: - ~some_boost_exception() throw() - { - } + some_boost_exception:: + ~some_boost_exception() throw() + { + } - inline - some_std_exception:: - some_std_exception( int x ): - x_(x) - { - } + inline + some_std_exception:: + some_std_exception( int x ): + x_(x) + { + } - some_std_exception:: - ~some_std_exception() throw() - { - } + some_std_exception:: + ~some_std_exception() throw() + { + } - template <> - void - throw_test_exception( int x ) - { - boost::throw_exception( some_boost_exception(x) ); - } + template <> + void + throw_test_exception( int x ) + { + boost::throw_exception( some_boost_exception(x) ); + } - template <> - void - throw_test_exception( int x ) - { - boost::throw_exception( some_std_exception(x) ); - } - } - } + template <> + void + throw_test_exception( int x ) + { + boost::throw_exception( some_std_exception(x) ); + } + } + } diff --git a/test/helper2.hpp b/test/helper2.hpp index 3e74c97..23dae1c 100644 --- a/test/helper2.hpp +++ b/test/helper2.hpp @@ -10,38 +10,38 @@ namespace boost - { - namespace - exception_test - { - struct - some_boost_exception: - public boost::exception, - public std::exception - { - explicit some_boost_exception( int x ); - virtual ~some_boost_exception() throw(); - int x_; - }; + { + namespace + exception_test + { + struct + some_boost_exception: + public boost::exception, + public std::exception + { + explicit some_boost_exception( int x ); + virtual ~some_boost_exception() throw(); + int x_; + }; - struct - some_std_exception: - public std::exception - { - explicit some_std_exception( int x ); - virtual ~some_std_exception() throw(); - int x_; - }; + struct + some_std_exception: + public std::exception + { + explicit some_std_exception( int x ); + virtual ~some_std_exception() throw(); + int x_; + }; - template - void throw_test_exception( int ); + template + void throw_test_exception( int ); - template <> - void throw_test_exception( int ); + template <> + void throw_test_exception( int ); - template <> - void throw_test_exception( int ); - } - } + template <> + void throw_test_exception( int ); + } + } #endif diff --git a/test/throw_exception_test.cpp b/test/throw_exception_test.cpp index 78d64d0..7f5ddfd 100644 --- a/test/throw_exception_test.cpp +++ b/test/throw_exception_test.cpp @@ -12,60 +12,60 @@ typedef boost::error_info test_int; void throw_fwd( void (*thrower)(int) ) - { - try - { - thrower(42); - } - catch( - boost::exception & x ) - { - x << test_int(42); - throw; - } - } + { + try + { + thrower(42); + } + catch( + boost::exception & x ) + { + x << test_int(42); + throw; + } + } template void tester() - { - try - { - throw_fwd( &boost::exception_test::throw_test_exception ); - BOOST_ASSERT(false); - } - catch( - std::exception & x ) - { - boost::exception_ptr p = boost::clone_exception(x); - try - { - rethrow_exception(p); - BOOST_TEST(false); - } - catch( - T & y ) - { - BOOST_TEST(*boost::get_error_info(y)==42); - BOOST_TEST(y.x_==42); - } - catch( - ... ) - { - BOOST_TEST(false); - } - } - catch( - ... ) - { - BOOST_TEST(false); - } - } + { + try + { + throw_fwd( &boost::exception_test::throw_test_exception ); + BOOST_ASSERT(false); + } + catch( + std::exception & x ) + { + boost::exception_ptr p = boost::clone_exception(x); + try + { + rethrow_exception(p); + BOOST_TEST(false); + } + catch( + T & y ) + { + BOOST_TEST(*boost::get_error_info(y)==42); + BOOST_TEST(y.x_==42); + } + catch( + ... ) + { + BOOST_TEST(false); + } + } + catch( + ... ) + { + BOOST_TEST(false); + } + } int main() - { - tester(); - tester(); - return boost::report_errors(); - } + { + tester(); + tester(); + return boost::report_errors(); + } diff --git a/test/to_string_test.cpp b/test/to_string_test.cpp index e56a2fa..c8dcd32 100644 --- a/test/to_string_test.cpp +++ b/test/to_string_test.cpp @@ -9,89 +9,89 @@ namespace n1 - { - class - c1 - { - }; + { + class + c1 + { + }; - std::string - to_string( c1 const & ) - { - return "c1"; - } - } + std::string + to_string( c1 const & ) + { + return "c1"; + } + } namespace n2 - { - class - c2 - { - }; + { + class + c2 + { + }; - std::ostream & - operator<<( std::ostream & s, c2 const & ) - { - s << "c2"; - return s; - } - } + std::ostream & + operator<<( std::ostream & s, c2 const & ) + { + s << "c2"; + return s; + } + } namespace n3 - { - class - c3 - { - }; + { + class + c3 + { + }; - std::ostream & - operator<<( std::ostream & s, c3 const & ) - { - s << "bad"; - return s; - } + std::ostream & + operator<<( std::ostream & s, c3 const & ) + { + s << "bad"; + return s; + } - std::string - to_string( c3 const & ) - { - return "c3"; - } - } + std::string + to_string( c3 const & ) + { + return "c3"; + } + } namespace boost - { - class - to_string_tester - { - }; - } + { + class + to_string_tester + { + }; + } template struct my_stub - { - std::string - operator()( T const & ) - { - return "stub"; - } - }; + { + std::string + operator()( T const & ) + { + return "stub"; + } + }; int main() - { - using namespace boost; - BOOST_TEST( to_string(5)=="5" ); - BOOST_TEST( to_string(n1::c1())=="c1" ); - BOOST_TEST( to_string(n2::c2())=="c2" ); - BOOST_TEST( to_string(n3::c3())=="c3" ); - BOOST_TEST( to_string_stub(5)=="5" ); - BOOST_TEST( to_string_stub(n1::c1())=="c1" ); - BOOST_TEST( to_string_stub(n2::c2())=="c2" ); - BOOST_TEST( to_string_stub(n3::c3())=="c3" ); - BOOST_TEST( to_string_stub(to_string_tester(),my_stub())=="stub" ); - return boost::report_errors(); - } + { + using namespace boost; + BOOST_TEST( to_string(5)=="5" ); + BOOST_TEST( to_string(n1::c1())=="c1" ); + BOOST_TEST( to_string(n2::c2())=="c2" ); + BOOST_TEST( to_string(n3::c3())=="c3" ); + BOOST_TEST( to_string_stub(5)=="5" ); + BOOST_TEST( to_string_stub(n1::c1())=="c1" ); + BOOST_TEST( to_string_stub(n2::c2())=="c2" ); + BOOST_TEST( to_string_stub(n3::c3())=="c3" ); + BOOST_TEST( to_string_stub(to_string_tester(),my_stub())=="stub" ); + return boost::report_errors(); + } diff --git a/test/unknown_exception_test.cpp b/test/unknown_exception_test.cpp index 030ea8d..9e46727 100644 --- a/test/unknown_exception_test.cpp +++ b/test/unknown_exception_test.cpp @@ -11,74 +11,74 @@ typedef boost::error_info test; struct test_boost_exception: - boost::exception - { - }; + boost::exception + { + }; void throw_boost_exception() - { - throw test_boost_exception() << test(42); - } + { + throw test_boost_exception() << test(42); + } void throw_unknown_exception() - { - struct - test_exception: - std::exception - { - }; - throw test_exception(); - } + { + struct + test_exception: + std::exception + { + }; + throw test_exception(); + } int main() - { - try - { - throw_boost_exception(); - } - catch( - boost::exception & x ) - { - boost::exception_ptr ep=boost::clone_exception(x); - try - { - rethrow_exception(ep); - } - catch( - boost::unknown_exception & x ) - { - BOOST_TEST( 42==*boost::get_error_info(x) ); - } - catch( - ... ) - { - BOOST_TEST(false); - } - } - try - { - throw_unknown_exception(); - } - catch( - std::exception & x ) - { - boost::exception_ptr ep=boost::clone_exception(x); - try - { - rethrow_exception(ep); - } - catch( - boost::unknown_exception & ) - { - } - catch( - ... ) - { - BOOST_TEST(false); - } - } - return boost::report_errors(); - } + { + try + { + throw_boost_exception(); + } + catch( + boost::exception & x ) + { + boost::exception_ptr ep=boost::clone_exception(x); + try + { + rethrow_exception(ep); + } + catch( + boost::unknown_exception & x ) + { + BOOST_TEST( 42==*boost::get_error_info(x) ); + } + catch( + ... ) + { + BOOST_TEST(false); + } + } + try + { + throw_unknown_exception(); + } + catch( + std::exception & x ) + { + boost::exception_ptr ep=boost::clone_exception(x); + try + { + rethrow_exception(ep); + } + catch( + boost::unknown_exception & ) + { + } + catch( + ... ) + { + BOOST_TEST(false); + } + } + return boost::report_errors(); + } diff --git a/test/what_test.cpp b/test/what_test.cpp index 71e443a..84fbd3d 100644 --- a/test/what_test.cpp +++ b/test/what_test.cpp @@ -10,18 +10,18 @@ typedef boost::error_info test; class my_exception: - public boost::exception - { - }; + public boost::exception + { + }; int main() - { - my_exception x; - x << test(1); - std::string w1 = x.what(); - x << test(2); - std::string w2 = x.what(); - BOOST_TEST( w1!=w2 ); - return boost::report_errors(); - } + { + my_exception x; + x << test(1); + std::string w1 = x.what(); + x << test(2); + std::string w2 = x.what(); + BOOST_TEST( w1!=w2 ); + return boost::report_errors(); + }