fc::error_report to fc::exception_ptr to enable inter-thread, inter-process error reports

This commit is contained in:
Daniel Larimer 2012-12-13 13:57:49 -05:00
parent cf10bac3db
commit e42af7c066
4 changed files with 13 additions and 8 deletions

View file

@ -3,6 +3,7 @@
#include <fc/string.hpp>
#include <fc/value.hpp>
#include <fc/optional.hpp>
#include <fc/exception.hpp>
namespace fc {
@ -49,15 +50,17 @@ namespace fc {
fc::string to_string()const;
fc::string to_detail_string()const;
error_context stack; ///< Human readable stack of what we were atempting to do.
fc::exception_ptr copy_exception();
};
} // namespace fc
#include <fc/reflect.hpp>
FC_REFLECT( fc::error_frame, (desc)(file)(line)(method)(time)(meta) )
FC_REFLECT( fc::error_report, (stack) )
#include <fc/exception.hpp>
#define FC_REPORT( X, ... ) fc::error_report X( __FILE__, __LINE__, __func__, __VA_ARGS__ )
#define FC_THROW_REPORT( ... ) FC_THROW( fc::error_report( __FILE__, __LINE__, __func__, __VA_ARGS__ ))
#define FC_REPORT_CURRENT(ER, ... ) (ER).pop_frame().push_frame( __FILE__, __LINE__, __func__, __VA_ARGS__ )

View file

@ -48,7 +48,7 @@ namespace fc {
try { throw e; } catch (...) { return current_exception(); }
return exception_ptr();
}
void rethrow_exception( const exception_ptr& e );
void rethrow_exception( const exception_ptr& e );
void throw_exception( const char* func, const char* file, int line, const char* msg );
void throw_exception_( const char* func, const char* file, int line, const char* msg,

View file

@ -3,6 +3,7 @@
#include <fc/sstream.hpp>
#include <fc/value.hpp>
#include <fc/json.hpp>
#include <boost/exception_ptr.hpp>
namespace fc {
error_frame::error_frame( const fc::string& f, uint64_t l, const fc::string& m, const fc::string& d, fc::value met )
@ -137,5 +138,8 @@ fc::string error_report::to_detail_string()const {
}
return ss.str();
}
fc::exception_ptr error_report::copy_exception() {
return boost::copy_exception(*this);
}
} // namespace fc

View file

@ -106,13 +106,11 @@ namespace fc { namespace json {
} else {
auto e_itr = v.find( "error" );
if( e_itr != end ) {
cur->set_exception(
fc::copy_exception(
fc::generic_exception(
value_cast<fc::string>(
e_itr->val["message"] ) ) ) );
cur->set_exception( fc::value_cast<error_report>(e_itr->val["data"]).copy_exception() );
} else {
elog( "no result nor error field" );
}
}
}
} catch( ... ) {
cur->set_exception( fc::current_exception() );
}