diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index 19ce75f..e6c686e 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -110,6 +110,9 @@ namespace fc friend void to_variant( const exception& e, variant& v ); friend void from_variant( const variant& e, exception& ll ); + + exception& operator=( const exception& copy ); + exception& operator=( exception&& copy ); protected: std::unique_ptr my; }; diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 564af9d..50f4db2 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -15,6 +15,42 @@ namespace fc { namespace raw { + template + inline void pack( Stream& s, const fc::exception& e ) + { + fc::raw::pack( s, e.code() ); + fc::raw::pack( s, std::string(e.name()) ); + fc::raw::pack( s, std::string(e.what()) ); + fc::raw::pack( s, e.get_log() ); + } + template + inline void unpack( Stream& s, fc::exception& e ) + { + int64_t code; + std::string name, what; + log_messages msgs; + + fc::raw::unpack( s, code ); + fc::raw::unpack( s, name ); + fc::raw::unpack( s, what ); + fc::raw::unpack( s, msgs ); + + e = fc::exception( fc::move(msgs), code, name, what ); + } + + template + inline void pack( Stream& s, const fc::log_message& msg ) + { + fc::raw::pack( s, variant(msg) ); + } + template + inline void unpack( Stream& s, fc::log_message& msg ) + { + fc::variant vmsg; + fc::raw::unpack( s, vmsg ); + msg = vmsg.as(); + } + template inline void pack( Stream& s, const fc::path& tp ) { diff --git a/include/fc/log/log_message.hpp b/include/fc/log/log_message.hpp index 4a6257a..4a96b00 100644 --- a/include/fc/log/log_message.hpp +++ b/include/fc/log/log_message.hpp @@ -132,6 +132,8 @@ namespace fc } // namespace fc +FC_REFLECT_TYPENAME( fc::log_message ); + #ifndef __func__ #define __func__ __FUNCTION__ #endif diff --git a/include/fc/reflect/typename.hpp b/include/fc/reflect/typename.hpp index 9329023..64f57bc 100644 --- a/include/fc/reflect/typename.hpp +++ b/include/fc/reflect/typename.hpp @@ -3,6 +3,7 @@ #include namespace fc { class value; + class exception; template class get_typename{}; template<> struct get_typename { static const char* name() { return "int32_t"; } }; template<> struct get_typename { static const char* name() { return "int64_t"; } }; @@ -18,7 +19,8 @@ namespace fc { template<> struct get_typename { static const char* name() { return "char"; } }; template<> struct get_typename { static const char* name() { return "char"; } }; template<> struct get_typename { static const char* name() { return "string"; } }; - template<> struct get_typename { static const char* name() { return "value"; } }; + template<> struct get_typename { static const char* name() { return "value"; } }; + template<> struct get_typename { static const char* name() { return "fc::exception"; } }; template<> struct get_typename> { static const char* name() { return "std::vector"; } }; struct signed_int; diff --git a/src/exception.cpp b/src/exception.cpp index 816b60c..186317c 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -32,6 +32,16 @@ namespace fc log_messages _elog; }; } + exception::exception( log_messages&& msgs, int64_t code, + const std::string& name_value, + const std::string& what_value ) + :my( new detail::exception_impl() ) + { + my->_code = code; + my->_what = what_value; + my->_name = name_value; + my->_elog = fc::move(msgs); + } unhandled_exception::unhandled_exception( log_message&& m, std::exception_ptr e ) :exception( fc::move(m) ) @@ -202,5 +212,16 @@ namespace fc throw null_optional(); return true; } + exception& exception::operator=( const exception& copy ) + { + *my = *copy.my; + return *this; + } + + exception& exception::operator=( exception&& copy ) + { + my = std::move(copy.my); + return *this; + } } // fc