0

How can I get the info (type + stack) about unhandled exception, thrown somewhere deep deep in a strange code, using the mechanism:

set_unexpected(my_unexpected()) ?

I doubt that this is possible. Is there any other way how to get exception type and in best case even call stack of the place where the unhandled throw was ?

Sold Out
  • 1,321
  • 14
  • 34
  • 2
    If you are on Linux, unhandled exceptions normally dump core. Open the core with gdb and inspect the stacktrace. – Maxim Egorushkin May 21 '15 at 13:28
  • 1
    "unhandled" (not caught) is not the same as "unexpected" (violating an exception specification). Unfortunately, there is no platform-independent information to retrieve in either handler - all you portably know is that *something* happened *somewhere*. – molbdnilo May 21 '15 at 13:29
  • Good point. Unfortunatelly I had to abbandon Linux for commertial reasons and work for the dark side now :D – Sold Out May 21 '15 at 18:59

1 Answers1

0

I have browsed a little more and found something of a good use.

My question could be rephrased: How do I resurrect an unhandled exception. Here is a solution:

// resurrect gone exception here
std::string ResurrectException()
{
   try 
   {
       throw;
   } 
   catch (const std::exception& e) 
   {
       return e.what();
   }
   catch (int intEx) 
   {
       char buffer[2];       
       sprintf(buffer,"%d",intEx);
       std::string outStr = buffer;
       return buffer;
   }
   catch (std::string strEx)
   {
        return strEx;
   }
   catch (char * buffEx)
   {
       std::string outStr = buffEx;
       return outStr;
   }
   // } catch (my_custom_exception_type& e) {
   //    return e.ToString(); }
   catch(...) 
   {
       return "unknown exception!";
   }
}

See here for details

I just wonder about the part "get the stack of the place where the exception was thrown". In C# standard System.Exception class carries information about stack as a string member. Unfortunatelly I don't see this in C++ standard system exceptions.

Community
  • 1
  • 1
Sold Out
  • 1,321
  • 14
  • 34