adding support for derived exceptions

This commit is contained in:
Daniel Larimer 2014-06-09 10:56:55 -04:00
parent 34ac1baf82
commit 374d71a1fd

View file

@ -210,31 +210,33 @@ namespace fc
}(); \ }(); \
#define FC_DECLARE_EXCEPTION( TYPE, CODE, WHAT ) \ #define FC_DECLARE_DERIVED_EXCEPTION( TYPE, BASE, CODE, WHAT ) \
class TYPE : public fc::exception \ class TYPE : public BASE \
{ \ { \
public: \ public: \
enum code_enum { \ enum code_enum { \
code_value = CODE, \ code_value = CODE, \
}; \ }; \
TYPE( fc::log_message&& m ) \ TYPE( fc::log_message&& m ) \
:exception( fc::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ){}\ :BASE( fc::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ){}\
TYPE( fc::log_messages msgs ) \ TYPE( fc::log_messages msgs ) \
:exception( fc::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \ :BASE( fc::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
TYPE( const TYPE& c ) \ TYPE( const TYPE& c ) \
:exception(c){} \ :BASE(c){} \
TYPE( const exception& c ) \ TYPE( const BASE& c ) \
:exception(c){} \ :BASE(c){} \
TYPE():exception(CODE, BOOST_PP_STRINGIZE(TYPE), WHAT){}\ TYPE():BASE(CODE, BOOST_PP_STRINGIZE(TYPE), WHAT){}\
\ \
virtual std::shared_ptr<exception> dynamic_copy_exception()const\ virtual std::shared_ptr<exception> dynamic_copy_exception()const\
{ return std::make_shared<TYPE>( *this ); } \ { return std::make_shared<TYPE>( *this ); } \
virtual NO_RETURN void dynamic_rethrow_exception()const \ virtual NO_RETURN void dynamic_rethrow_exception()const \
{ if( code() == CODE ) throw *this;\ { if( code() == CODE ) throw *this;\
else fc::exception::dynamic_rethrow_exception(); \ else BASE::dynamic_rethrow_exception(); \
} \ } \
}; };
#define FC_DECLARE_EXCEPTION( TYPE, CODE, WHAT ) \
FC_DECLARE_DERIVED_EXCEPTION( TYPE, fc::exception, CODE, WHAT )
FC_DECLARE_EXCEPTION( timeout_exception, timeout_exception_code, "Timeout" ); FC_DECLARE_EXCEPTION( timeout_exception, timeout_exception_code, "Timeout" );
FC_DECLARE_EXCEPTION( file_not_found_exception, file_not_found_exception_code, "File Not Found" ); FC_DECLARE_EXCEPTION( file_not_found_exception, file_not_found_exception_code, "File Not Found" );