Add exception handling to to_string and to_detail_string
This commit is contained in:
parent
d729816b06
commit
2eb047a6f4
1 changed files with 42 additions and 6 deletions
|
|
@ -183,9 +183,17 @@ namespace fc
|
|||
string exception::to_detail_string( log_level ll )const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << variant(my->_code).as_string() <<" " << my->_name << ": " <<my->_what<<"\n";
|
||||
for( auto itr = my->_elog.begin(); itr != my->_elog.end(); )
|
||||
{
|
||||
try {
|
||||
try {
|
||||
ss << variant( my->_code ).as_string();
|
||||
} catch( std::bad_alloc& ) {
|
||||
throw;
|
||||
} catch( ... ) {
|
||||
ss << "<- exception in to_detail_string.";
|
||||
}
|
||||
ss << " " << my->_name << ": " << my->_what << "\n";
|
||||
for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ) {
|
||||
try {
|
||||
ss << itr->get_message() <<"\n"; //fc::format_string( itr->get_format(), itr->get_data() ) <<"\n";
|
||||
try
|
||||
{
|
||||
|
|
@ -197,8 +205,18 @@ namespace fc
|
|||
}
|
||||
ss << " " << itr->get_context().to_string();
|
||||
++itr;
|
||||
} catch( std::bad_alloc& ) {
|
||||
throw;
|
||||
} catch( ... ) {
|
||||
ss << "<- exception in to_detail_string.";
|
||||
}
|
||||
if( itr != my->_elog.end() ) ss<<"\n";
|
||||
}
|
||||
} catch( std::bad_alloc& ) {
|
||||
throw;
|
||||
} catch( ... ) {
|
||||
ss << "<- exception in to_detail_string.\n";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
|
@ -208,13 +226,31 @@ namespace fc
|
|||
string exception::to_string( log_level ll )const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << what() << " (" << variant(my->_code).as_string() <<")\n";
|
||||
for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr )
|
||||
{
|
||||
try {
|
||||
ss << my->_what;
|
||||
try {
|
||||
ss << " (" << variant( my->_code ).as_string() << ")\n";
|
||||
} catch( std::bad_alloc& ) {
|
||||
throw;
|
||||
} catch( ... ) {
|
||||
ss << "<- exception in to_string.\n";
|
||||
}
|
||||
for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) {
|
||||
try {
|
||||
ss << fc::format_string( itr->get_format(), itr->get_data() ) << "\n";
|
||||
// ss << " " << itr->get_context().to_string() <<"\n";
|
||||
} catch( std::bad_alloc& ) {
|
||||
throw;
|
||||
} catch( ... ) {
|
||||
ss << "<- exception in to_string.\n";
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
} catch( std::bad_alloc& ) {
|
||||
throw;
|
||||
} catch( ... ) {
|
||||
ss << "<- exception in to_string.\n";
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void exception_factory::rethrow( const exception& e )const
|
||||
|
|
|
|||
Loading…
Reference in a new issue