BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
exception.hpp File Reference

Defines exception's used by fc. More...

#include <fc/log/logger.hpp>
#include <fc/optional.hpp>
#include <exception>
#include <functional>
#include <unordered_map>

Go to the source code of this file.

Classes

class  fc::exception
 Used to generate a useful error report when an exception is thrown. More...
 
class  fc::unhandled_exception
 re-thrown whenever an unhandled exception is caught. More...
 
class  fc::exception_factory
 
struct  fc::exception_factory::base_exception_builder
 
struct  fc::exception_factory::exception_builder< T >
 

Namespaces

 fc
 
 fc::detail
 

Macros

#define FC_REGISTER_EXCEPTION(r, unused, base)   fc::exception_factory::instance().register_exception<base>();
 
#define FC_REGISTER_EXCEPTIONS(SEQ)
 
#define FC_DECLARE_DERIVED_EXCEPTION(TYPE, BASE, CODE)
 
#define FC_IMPLEMENT_DERIVED_EXCEPTION(TYPE, BASE, CODE, WHAT)
 
#define FC_DECLARE_EXCEPTION(TYPE, CODE)   FC_DECLARE_DERIVED_EXCEPTION( TYPE, fc::exception, CODE )
 
#define FC_IMPLEMENT_EXCEPTION(TYPE, CODE, WHAT)   FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, fc::exception, CODE, WHAT )
 
#define LIKELY(x)   (x)
 
#define UNLIKELY(x)   (x)
 
#define FC_EXPAND_MACRO(x)   x
 : Workaround for varying preprocessing behavior between MSVC and gcc More...
 
#define FC_ASSERT(TEST, ...)
 Checks a condition and throws an assert_exception if the test is FALSE. More...
 
#define FC_CAPTURE_AND_THROW(EXCEPTION_TYPE, ...)
 
#define FC_INDIRECT_EXPAND(MACRO, ARGS)   MACRO ARGS
 
#define FC_THROW( ...)
 
#define FC_EXCEPTION(EXCEPTION_TYPE, FORMAT, ...)   EXCEPTION_TYPE( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) )
 
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT, ...)
 
#define FC_RETHROW_EXCEPTION(ER, LOG_LEVEL, FORMAT, ...)
 Appends a log_message to the exception ER and rethrows it. More...
 
#define FC_LOG_AND_RETHROW()
 
#define FC_CAPTURE_LOG_AND_RETHROW(...)
 
#define FC_CAPTURE_AND_LOG(...)
 
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT, ...)
 Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log message. More...
 
#define FC_CAPTURE_AND_RETHROW(...)
 

Typedefs

typedef std::shared_ptr< exception > fc::exception_ptr
 
typedef optional< exception > fc::oexception
 

Enumerations

enum  fc::exception_code {
  fc::unspecified_exception_code = 0, fc::unhandled_exception_code = 1, fc::timeout_exception_code = 2, fc::file_not_found_exception_code = 3,
  fc::parse_error_exception_code = 4, fc::invalid_arg_exception_code = 5, fc::key_not_found_exception_code = 6, fc::bad_cast_exception_code = 7,
  fc::out_of_range_exception_code = 8, fc::canceled_exception_code = 9, fc::assert_exception_code = 10, fc::eof_exception_code = 11,
  fc::std_exception_code = 13, fc::invalid_operation_exception_code = 14, fc::unknown_host_exception_code = 15, fc::null_optional_code = 16,
  fc::aes_error_code = 18, fc::overflow_code = 19, fc::underflow_code = 20, fc::divide_by_zero_code = 21,
  fc::method_not_found_exception_code = 22
}
 

Functions

void fc::to_variant (const exception &e, variant &v, uint32_t max_depth)
 
void fc::from_variant (const variant &e, exception &ll, uint32_t max_depth)
 
template<typename T >
fc::exception_ptr fc::copy_exception (T &&e)
 
 fc::FC_DECLARE_EXCEPTION (timeout_exception, timeout_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (file_not_found_exception, file_not_found_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (parse_error_exception, parse_error_exception_code)
 reports parse errors More...
 
 fc::FC_DECLARE_EXCEPTION (invalid_arg_exception, invalid_arg_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (key_not_found_exception, key_not_found_exception_code)
 reports when a key, guid, or other item is not found. More...
 
 fc::FC_DECLARE_EXCEPTION (bad_cast_exception, bad_cast_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (out_of_range_exception, out_of_range_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (method_not_found_exception, method_not_found_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (invalid_operation_exception, invalid_operation_exception_code)
 if an operation is unsupported or not valid this may be thrown More...
 
 fc::FC_DECLARE_EXCEPTION (unknown_host_exception, unknown_host_exception_code)
 if an host name can not be resolved this may be thrown More...
 
 fc::FC_DECLARE_EXCEPTION (canceled_exception, canceled_exception_code)
 used to report a canceled Operation More...
 
 fc::FC_DECLARE_EXCEPTION (assert_exception, assert_exception_code)
 used inplace of assert() to report violations of pre conditions. More...
 
 fc::FC_DECLARE_EXCEPTION (eof_exception, eof_exception_code)
 
 fc::FC_DECLARE_EXCEPTION (null_optional, null_optional_code)
 
 fc::FC_DECLARE_EXCEPTION (aes_exception, aes_error_code)
 
 fc::FC_DECLARE_EXCEPTION (overflow_exception, overflow_code)
 
 fc::FC_DECLARE_EXCEPTION (underflow_exception, underflow_code)
 
 fc::FC_DECLARE_EXCEPTION (divide_by_zero_exception, divide_by_zero_code)
 
std::string fc::except_str ()
 
void fc::record_assert_trip (const char *filename, uint32_t lineno, const char *expr)
 

Variables

bool fc::enable_record_assert_trip = false
 

Detailed Description

Defines exception's used by fc.

Definition in file exception.hpp.

Macro Definition Documentation

◆ FC_ASSERT

#define FC_ASSERT (   TEST,
  ... 
)
Value:
if( UNLIKELY(!(TEST)) ) \
{ \
fc::record_assert_trip( __FILE__, __LINE__, #TEST ); \
FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \
} \
FC_MULTILINE_MACRO_END \
)

Checks a condition and throws an assert_exception if the test is FALSE.

Definition at line 345 of file exception.hpp.

◆ FC_CAPTURE_AND_LOG

#define FC_CAPTURE_AND_LOG (   ...)
Value:
catch( fc::exception& er ) { \
wlog( "${details}", ("details",er.to_detail_string()) ); \
wdump( __VA_ARGS__ ); \
} catch( const std::exception& e ) { \
fc::exception fce( \
FC_LOG_MESSAGE( warn, "rethrow ${what}: ",FC_FORMAT_ARG_PARAMS( __VA_ARGS__ )("what",e.what()) ), \
typeid(e).name(), \
e.what() ) ; \
wlog( "${details}", ("details",fce.to_detail_string()) ); \
wdump( __VA_ARGS__ ); \
} catch( ... ) { \
fc::unhandled_exception e( \
FC_LOG_MESSAGE( warn, "rethrow", FC_FORMAT_ARG_PARAMS( __VA_ARGS__) ), \
std::current_exception() ); \
wlog( "${details}", ("details",e.to_detail_string()) ); \
wdump( __VA_ARGS__ ); \
}

Definition at line 438 of file exception.hpp.

◆ FC_CAPTURE_AND_RETHROW

#define FC_CAPTURE_AND_RETHROW (   ...)
Value:
catch( fc::exception& er ) { \
FC_RETHROW_EXCEPTION( er, warn, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ); \
} catch( const std::exception& e ) { \
throw fc::exception( \
FC_LOG_MESSAGE( warn, "${what}: ",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)("what",e.what())), \
typeid(e).name(), \
e.what() ) ;\
} catch( ... ) { \
FC_LOG_MESSAGE( warn, "",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)), \
std::current_exception() ); \
}

Definition at line 479 of file exception.hpp.

◆ FC_CAPTURE_AND_THROW

#define FC_CAPTURE_AND_THROW (   EXCEPTION_TYPE,
  ... 
)
Value:
FC_MULTILINE_MACRO_BEGIN \
throw EXCEPTION_TYPE( FC_LOG_MESSAGE( error, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ) ); \
FC_MULTILINE_MACRO_END

Definition at line 357 of file exception.hpp.

◆ FC_CAPTURE_LOG_AND_RETHROW

#define FC_CAPTURE_LOG_AND_RETHROW (   ...)
Value:
catch( fc::exception& er ) { \
wlog( "${details}", ("details",er.to_detail_string()) ); \
wdump( __VA_ARGS__ ); \
FC_RETHROW_EXCEPTION( er, warn, "rethrow", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ); \
} catch( const std::exception& e ) { \
fc::exception fce( \
FC_LOG_MESSAGE( warn, "rethrow ${what}: ", FC_FORMAT_ARG_PARAMS( __VA_ARGS__ )("what",e.what())), \
typeid(e).name(), \
e.what() ) ; \
wlog( "${details}", ("details",fce.to_detail_string()) ); \
wdump( __VA_ARGS__ ); \
throw fce;\
} catch( ... ) { \
fc::unhandled_exception e( \
FC_LOG_MESSAGE( warn, "rethrow", FC_FORMAT_ARG_PARAMS( __VA_ARGS__) ), \
std::current_exception() ); \
wlog( "${details}", ("details",e.to_detail_string()) ); \
wdump( __VA_ARGS__ ); \
throw e; \
}

Definition at line 415 of file exception.hpp.

◆ FC_DECLARE_DERIVED_EXCEPTION

#define FC_DECLARE_DERIVED_EXCEPTION (   TYPE,
  BASE,
  CODE 
)
Value:
class TYPE : public BASE \
{ \
public: \
enum code_enum { \
code_value = CODE, \
}; \
explicit TYPE( int64_t code, const std::string& name_value, const std::string& what_value ); \
explicit TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ); \
explicit TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value );\
explicit TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value );\
explicit TYPE( const std::string& what_value, const fc::log_messages& m ); \
explicit TYPE( fc::log_message&& m ); \
explicit TYPE( fc::log_messages msgs ); \
TYPE( TYPE&& c ) = default; \
TYPE( const TYPE& c ); \
TYPE( const BASE& c ); \
explicit TYPE();\
\
virtual std::shared_ptr<fc::exception> dynamic_copy_exception()const;\
[[noreturn]] virtual void dynamic_rethrow_exception()const; \
};

Definition at line 226 of file exception.hpp.

◆ FC_DECLARE_EXCEPTION

#define FC_DECLARE_EXCEPTION (   TYPE,
  CODE 
)    FC_DECLARE_DERIVED_EXCEPTION( TYPE, fc::exception, CODE )

Definition at line 278 of file exception.hpp.

◆ FC_EXCEPTION

#define FC_EXCEPTION (   EXCEPTION_TYPE,
  FORMAT,
  ... 
)    EXCEPTION_TYPE( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) )

Definition at line 371 of file exception.hpp.

◆ FC_EXPAND_MACRO

#define FC_EXPAND_MACRO (   x)    x

: Workaround for varying preprocessing behavior between MSVC and gcc

Definition at line 341 of file exception.hpp.

◆ FC_IMPLEMENT_DERIVED_EXCEPTION

#define FC_IMPLEMENT_DERIVED_EXCEPTION (   TYPE,
  BASE,
  CODE,
  WHAT 
)
Value:
TYPE::TYPE( int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( code, name_value, what_value ) {} \
TYPE::TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( std::move(m), code, name_value, what_value ) {} \
TYPE::TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( std::move(m), code, name_value, what_value ) {} \
TYPE::TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( m, code, name_value, what_value ) {} \
TYPE::TYPE( const std::string& what_value, const fc::log_messages& m ) \
: BASE( m, CODE, BOOST_PP_STRINGIZE(TYPE), what_value ) {} \
TYPE::TYPE( fc::log_message&& m ) \
: BASE( std::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
TYPE::TYPE( fc::log_messages msgs ) \
: BASE( std::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
TYPE::TYPE( const TYPE& c ) : BASE(c) {} \
TYPE::TYPE( const BASE& c ) : BASE(c) {} \
TYPE::TYPE() : BASE(CODE, BOOST_PP_STRINGIZE(TYPE), WHAT) {} \
\
std::shared_ptr<fc::exception> TYPE::dynamic_copy_exception()const \
{ \
return std::make_shared<TYPE>( *this ); \
} \
[[noreturn]] void TYPE::dynamic_rethrow_exception()const \
{ \
if( code() == CODE ) throw *this;\
}

Definition at line 249 of file exception.hpp.

◆ FC_IMPLEMENT_EXCEPTION

#define FC_IMPLEMENT_EXCEPTION (   TYPE,
  CODE,
  WHAT 
)    FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, fc::exception, CODE, WHAT )

Definition at line 281 of file exception.hpp.

◆ FC_INDIRECT_EXPAND

#define FC_INDIRECT_EXPAND (   MACRO,
  ARGS 
)    MACRO ARGS

Definition at line 365 of file exception.hpp.

◆ FC_LOG_AND_RETHROW

#define FC_LOG_AND_RETHROW ( )
Value:
catch( fc::exception& er ) { \
wlog( "${details}", ("details",er.to_detail_string()) ); \
FC_RETHROW_EXCEPTION( er, warn, "rethrow" ); \
} catch( const std::exception& e ) { \
fc::exception fce( \
FC_LOG_MESSAGE( warn, "rethrow ${what}: ", ("what",e.what())), \
typeid(e).name(), \
e.what() ) ; \
wlog( "${details}", ("details",fce.to_detail_string()) ); \
throw fce;\
} catch( ... ) { \
fc::unhandled_exception e( \
FC_LOG_MESSAGE( warn, "rethrow"), \
std::current_exception() ); \
wlog( "${details}", ("details",e.to_detail_string()) ); \
throw e; \
}

Definition at line 395 of file exception.hpp.

◆ FC_REGISTER_EXCEPTION

#define FC_REGISTER_EXCEPTION (   r,
  unused,
  base 
)    fc::exception_factory::instance().register_exception<base>();

Definition at line 215 of file exception.hpp.

◆ FC_REGISTER_EXCEPTIONS

#define FC_REGISTER_EXCEPTIONS (   SEQ)
Value:
\
static bool exception_init = []()->bool{ \
BOOST_PP_SEQ_FOR_EACH( FC_REGISTER_EXCEPTION, v, SEQ ) \
return true; \
}(); \

Definition at line 218 of file exception.hpp.

◆ FC_RETHROW_EXCEPTION

#define FC_RETHROW_EXCEPTION (   ER,
  LOG_LEVEL,
  FORMAT,
  ... 
)
Value:
FC_MULTILINE_MACRO_BEGIN \
ER.append_log( FC_LOG_MESSAGE( LOG_LEVEL, FORMAT, __VA_ARGS__ ) ); \
throw; \
FC_MULTILINE_MACRO_END

Appends a log_message to the exception ER and rethrows it.

Definition at line 389 of file exception.hpp.

◆ FC_RETHROW_EXCEPTIONS

#define FC_RETHROW_EXCEPTIONS (   LOG_LEVEL,
  FORMAT,
  ... 
)
Value:
catch( fc::exception& er ) { \
FC_RETHROW_EXCEPTION( er, LOG_LEVEL, FORMAT, __VA_ARGS__ ); \
} catch( const std::exception& e ) { \
throw fc::exception( \
FC_LOG_MESSAGE( LOG_LEVEL, "${what}: " FORMAT,__VA_ARGS__("what",e.what())), \
typeid(e).name(), \
e.what() ) ;\
} catch( ... ) { \
FC_LOG_MESSAGE( LOG_LEVEL, FORMAT,__VA_ARGS__), \
std::current_exception() ); \
}

Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log message.

Definition at line 464 of file exception.hpp.

◆ FC_THROW

#define FC_THROW (   ...)
Value:
FC_MULTILINE_MACRO_BEGIN \
throw fc::exception( FC_INDIRECT_EXPAND(FC_LOG_MESSAGE, ( error, __VA_ARGS__ )) ); \
FC_MULTILINE_MACRO_END

Definition at line 366 of file exception.hpp.

◆ FC_THROW_EXCEPTION

#define FC_THROW_EXCEPTION (   EXCEPTION,
  FORMAT,
  ... 
)
Value:
FC_MULTILINE_MACRO_BEGIN \
throw EXCEPTION( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) ); \
FC_MULTILINE_MACRO_END
Parameters
EXCEPTIONa class in the Phoenix::Athena::API namespace that inherits
FORMATa const char* string with "${keys}"
...other parameters

Definition at line 379 of file exception.hpp.

◆ LIKELY

#define LIKELY (   x)    (x)

Definition at line 334 of file exception.hpp.

◆ UNLIKELY

#define UNLIKELY (   x)    (x)

Definition at line 335 of file exception.hpp.

FC_MULTILINE_MACRO_BEGIN
#define FC_MULTILINE_MACRO_BEGIN
Definition: logger.hpp:65
fc::exception
Used to generate a useful error report when an exception is thrown.
Definition: exception.hpp:56
FC_EXPAND_MACRO
#define FC_EXPAND_MACRO(x)
: Workaround for varying preprocessing behavior between MSVC and gcc
Definition: exception.hpp:341
fc::enable_record_assert_trip
bool enable_record_assert_trip
Definition: exception.cpp:337
FC_REGISTER_EXCEPTION
#define FC_REGISTER_EXCEPTION(r, unused, base)
Definition: exception.hpp:215
FC_FORMAT_ARG_PARAMS
#define FC_FORMAT_ARG_PARAMS(...)
Definition: logger.hpp:154
FC_INDIRECT_EXPAND
#define FC_INDIRECT_EXPAND(MACRO, ARGS)
Definition: exception.hpp:365
fc::record_assert_trip
void record_assert_trip(const char *filename, uint32_t lineno, const char *expr)
Definition: exception.cpp:313
fc::exception::dynamic_rethrow_exception
virtual void dynamic_rethrow_exception() const
Definition: exception.cpp:262
fc::exception::to_detail_string
std::string to_detail_string(log_level ll=log_level::all) const
Definition: exception.cpp:183
fc::log_message
aggregates a message along with the context and associated meta-information.
Definition: log_message.hpp:106
fc::unhandled_exception
re-thrown whenever an unhandled exception is caught.
Definition: exception.hpp:146
fc::log_messages
std::vector< log_message > log_messages
Definition: log_message.hpp:134
fc::std_exception_code
@ std_exception_code
Definition: exception.hpp:31
FC_LOG_MESSAGE
#define FC_LOG_MESSAGE(LOG_LEVEL, FORMAT,...)
A helper method for generating log messages.
Definition: log_message.hpp:163
UNLIKELY
#define UNLIKELY(x)
Definition: exception.hpp:335