10 #include <unordered_map> 14 namespace detail {
class exception_impl; }
65 const std::string& name_value =
"exception",
66 const std::string& what_value =
"unspecified");
68 const std::string& name_value =
"exception",
69 const std::string& what_value =
"unspecified");
71 const std::string& name_value =
"exception",
72 const std::string& what_value =
"unspecified");
75 const std::string& name_value =
"exception",
76 const std::string& what_value =
"unspecified");
81 const char* name()
const throw();
82 int64_t code()const throw();
83 virtual const
char* what()const throw();
109 [[noreturn]] virtual
void dynamic_rethrow_exception()const;
118 virtual
std::shared_ptr<
exception> dynamic_copy_exception()const;
126 std::unique_ptr<detail::exception_impl> my;
158 [[noreturn]]
virtual void dynamic_rethrow_exception()
const;
159 virtual std::shared_ptr<exception> dynamic_copy_exception()
const;
167 #if defined(_MSC_VER) && (_MSC_VER < 1700) 168 return std::make_shared<unhandled_exception>(
log_message(),
171 return std::make_shared<unhandled_exception>(
log_message(),
172 std::make_exception_ptr(std::forward<T>(e)) );
182 [[noreturn]]
virtual void rethrow(
const exception& e )
const = 0;
188 [[noreturn]]
virtual void rethrow(
const exception& e )
const override 198 auto itr = _registered_exceptions.find( T::code_value );
199 assert( itr == _registered_exceptions.end() );
201 _registered_exceptions[T::code_value] = &builder;
204 [[noreturn]]
void rethrow(
const exception& e )
const;
213 std::unordered_map<int64_t,base_exception_builder*> _registered_exceptions;
215 #define FC_REGISTER_EXCEPTION(r, unused, base) \ 216 fc::exception_factory::instance().register_exception<base>(); 218 #define FC_REGISTER_EXCEPTIONS( SEQ )\ 220 static bool exception_init = []()->bool{ \ 221 BOOST_PP_SEQ_FOR_EACH( FC_REGISTER_EXCEPTION, v, SEQ ) \ 226 #define FC_DECLARE_DERIVED_EXCEPTION( TYPE, BASE, CODE ) \ 227 class TYPE : public BASE \ 233 explicit TYPE( int64_t code, const std::string& name_value, const std::string& what_value ); \ 234 explicit TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ); \ 235 explicit TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value );\ 236 explicit TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value );\ 237 explicit TYPE( const std::string& what_value, const fc::log_messages& m ); \ 238 explicit TYPE( fc::log_message&& m ); \ 239 explicit TYPE( fc::log_messages msgs ); \ 240 TYPE( TYPE&& c ) = default; \ 241 TYPE( const TYPE& c ); \ 242 TYPE( const BASE& c ); \ 245 virtual std::shared_ptr<fc::exception> dynamic_copy_exception()const;\ 246 [[noreturn]] virtual void dynamic_rethrow_exception()const; \ 249 #define FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, BASE, CODE, WHAT ) \ 250 TYPE::TYPE( int64_t code, const std::string& name_value, const std::string& what_value ) \ 251 : BASE( code, name_value, what_value ) {} \ 252 TYPE::TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \ 253 : BASE( std::move(m), code, name_value, what_value ) {} \ 254 TYPE::TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \ 255 : BASE( std::move(m), code, name_value, what_value ) {} \ 256 TYPE::TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value ) \ 257 : BASE( m, code, name_value, what_value ) {} \ 258 TYPE::TYPE( const std::string& what_value, const fc::log_messages& m ) \ 259 : BASE( m, CODE, BOOST_PP_STRINGIZE(TYPE), what_value ) {} \ 260 TYPE::TYPE( fc::log_message&& m ) \ 261 : BASE( std::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \ 262 TYPE::TYPE( fc::log_messages msgs ) \ 263 : BASE( std::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \ 264 TYPE::TYPE( const TYPE& c ) : BASE(c) {} \ 265 TYPE::TYPE( const BASE& c ) : BASE(c) {} \ 266 TYPE::TYPE() : BASE(CODE, BOOST_PP_STRINGIZE(TYPE), WHAT) {} \ 268 std::shared_ptr<fc::exception> TYPE::dynamic_copy_exception()const \ 270 return std::make_shared<TYPE>( *this ); \ 272 [[noreturn]] void TYPE::dynamic_rethrow_exception()const \ 274 if( code() == CODE ) throw *this;\ 275 else fc::exception::dynamic_rethrow_exception(); \ 278 #define FC_DECLARE_EXCEPTION( TYPE, CODE ) \ 279 FC_DECLARE_DERIVED_EXCEPTION( TYPE, fc::exception, CODE ) 281 #define FC_IMPLEMENT_EXCEPTION( TYPE, CODE, WHAT ) \ 282 FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, fc::exception, CODE, WHAT ) 322 const char* filename,
331 #define LIKELY(x) __builtin_expect((long)!!(x), 1L) 332 #define UNLIKELY(x) __builtin_expect((long)!!(x), 0L) 334 #define LIKELY(x) (x) 335 #define UNLIKELY(x) (x) 341 #define FC_EXPAND_MACRO( x ) x 345 #define FC_ASSERT( TEST, ... ) \ 347 FC_MULTILINE_MACRO_BEGIN \ 348 if( UNLIKELY(!(TEST)) ) \ 350 if( fc::enable_record_assert_trip ) \ 351 fc::record_assert_trip( __FILE__, __LINE__, #TEST ); \ 352 FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \ 354 FC_MULTILINE_MACRO_END \ 357 #define FC_CAPTURE_AND_THROW( EXCEPTION_TYPE, ... ) \ 358 FC_MULTILINE_MACRO_BEGIN \ 359 throw EXCEPTION_TYPE( FC_LOG_MESSAGE( error, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ) ); \ 360 FC_MULTILINE_MACRO_END 365 #define FC_INDIRECT_EXPAND(MACRO, ARGS) MACRO ARGS 366 #define FC_THROW( ... ) \ 367 FC_MULTILINE_MACRO_BEGIN \ 368 throw fc::exception( FC_INDIRECT_EXPAND(FC_LOG_MESSAGE, ( error, __VA_ARGS__ )) ); \ 369 FC_MULTILINE_MACRO_END 371 #define FC_EXCEPTION( EXCEPTION_TYPE, FORMAT, ... ) \ 372 EXCEPTION_TYPE( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) ) 379 #define FC_THROW_EXCEPTION( EXCEPTION, FORMAT, ... ) \ 380 FC_MULTILINE_MACRO_BEGIN \ 381 throw EXCEPTION( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) ); \ 382 FC_MULTILINE_MACRO_END 389 #define FC_RETHROW_EXCEPTION( ER, LOG_LEVEL, FORMAT, ... ) \ 390 FC_MULTILINE_MACRO_BEGIN \ 391 ER.append_log( FC_LOG_MESSAGE( LOG_LEVEL, FORMAT, __VA_ARGS__ ) ); \ 393 FC_MULTILINE_MACRO_END 395 #define FC_LOG_AND_RETHROW( ) \ 396 catch( fc::exception& er ) { \ 397 wlog( "${details}", ("details",er.to_detail_string()) ); \ 398 FC_RETHROW_EXCEPTION( er, warn, "rethrow" ); \ 399 } catch( const std::exception& e ) { \ 401 FC_LOG_MESSAGE( warn, "rethrow ${what}: ", ("what",e.what())), \ 402 fc::std_exception_code,\ 405 wlog( "${details}", ("details",fce.to_detail_string()) ); \ 408 fc::unhandled_exception e( \ 409 FC_LOG_MESSAGE( warn, "rethrow"), \ 410 std::current_exception() ); \ 411 wlog( "${details}", ("details",e.to_detail_string()) ); \ 415 #define FC_CAPTURE_LOG_AND_RETHROW( ... ) \ 416 catch( fc::exception& er ) { \ 417 wlog( "${details}", ("details",er.to_detail_string()) ); \ 418 wdump( __VA_ARGS__ ); \ 419 FC_RETHROW_EXCEPTION( er, warn, "rethrow", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ); \ 420 } catch( const std::exception& e ) { \ 422 FC_LOG_MESSAGE( warn, "rethrow ${what}: ", FC_FORMAT_ARG_PARAMS( __VA_ARGS__ )("what",e.what())), \ 423 fc::std_exception_code,\ 426 wlog( "${details}", ("details",fce.to_detail_string()) ); \ 427 wdump( __VA_ARGS__ ); \ 430 fc::unhandled_exception e( \ 431 FC_LOG_MESSAGE( warn, "rethrow", FC_FORMAT_ARG_PARAMS( __VA_ARGS__) ), \ 432 std::current_exception() ); \ 433 wlog( "${details}", ("details",e.to_detail_string()) ); \ 434 wdump( __VA_ARGS__ ); \ 438 #define FC_CAPTURE_AND_LOG( ... ) \ 439 catch( fc::exception& er ) { \ 440 wlog( "${details}", ("details",er.to_detail_string()) ); \ 441 wdump( __VA_ARGS__ ); \ 442 } catch( const std::exception& e ) { \ 444 FC_LOG_MESSAGE( warn, "rethrow ${what}: ",FC_FORMAT_ARG_PARAMS( __VA_ARGS__ )("what",e.what()) ), \ 445 fc::std_exception_code,\ 448 wlog( "${details}", ("details",fce.to_detail_string()) ); \ 449 wdump( __VA_ARGS__ ); \ 451 fc::unhandled_exception e( \ 452 FC_LOG_MESSAGE( warn, "rethrow", FC_FORMAT_ARG_PARAMS( __VA_ARGS__) ), \ 453 std::current_exception() ); \ 454 wlog( "${details}", ("details",e.to_detail_string()) ); \ 455 wdump( __VA_ARGS__ ); \ 464 #define FC_RETHROW_EXCEPTIONS( LOG_LEVEL, FORMAT, ... ) \ 465 catch( fc::exception& er ) { \ 466 FC_RETHROW_EXCEPTION( er, LOG_LEVEL, FORMAT, __VA_ARGS__ ); \ 467 } catch( const std::exception& e ) { \ 468 throw fc::exception( \ 469 FC_LOG_MESSAGE( LOG_LEVEL, "${what}: " FORMAT,__VA_ARGS__("what",e.what())), \ 470 fc::std_exception_code,\ 474 throw fc::unhandled_exception( \ 475 FC_LOG_MESSAGE( LOG_LEVEL, FORMAT,__VA_ARGS__), \ 476 std::current_exception() ); \ 479 #define FC_CAPTURE_AND_RETHROW( ... ) \ 480 catch( fc::exception& er ) { \ 481 FC_RETHROW_EXCEPTION( er, warn, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ); \ 482 } catch( const std::exception& e ) { \ 483 throw fc::exception( \ 484 FC_LOG_MESSAGE( warn, "${what}: ",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)("what",e.what())), \ 485 fc::std_exception_code,\ 489 throw fc::unhandled_exception( \ 490 FC_LOG_MESSAGE( warn, "",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)), \ 491 std::current_exception() ); \
fc::exception_ptr copy_exception(T &&e)
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
() file_not_found_exception() parse_error_exception() invalid_arg_exception() invalid_operation_exception() key_not_found_exception() bad_cast_exception() out_of_range_exception() canceled_exception() assert_exception() eof_exception() unknown_host_exception() null_optional() aes_exception() overflow_exception() underflow_exception(divide_by_zero_exception)) namespace detail
provides stack-based nullable value similar to boost::optional
std::shared_ptr< exception > exception_ptr
re-thrown whenever an unhandled exception is caught.Any exceptions thrown by 3rd party libraries that...
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
std::vector< log_message > log_messages
bool enable_record_assert_trip
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
void record_assert_trip(const char *filename, uint32_t lineno, const char *expr)
void register_exception()
FC_DECLARE_EXCEPTION(timeout_exception, timeout_exception_code)
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
std::string to_string(double)
aggregates a message along with the context and associated meta-information.
virtual void rethrow(const exception &e) const override
void copy(const path &from, const path &to)
static exception_factory & instance()
for unhandled 3rd party exceptions