Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get some information at least for catch(...)?

Is there any way to get at least some information inside of here?

...
catch(...)
{
  std::cerr << "Unhandled exception" << std::endl;
}

I have this as a last resort around all my code. Would it be better to let it crash, because then I at least could get a crash report?

like image 353
Net Citizen Avatar asked Dec 09 '22 20:12

Net Citizen


2 Answers

No, there isn't any way. Try making all your exception classes derive from one single class, like std::exception, and then catch that one.

You could rethrow in a nested try, though, in an attempt to figure out the type. But then you could aswell use a previous catch clause (and ... only as fall-back).

like image 116
Johannes Schaub - litb Avatar answered Mar 07 '23 02:03

Johannes Schaub - litb


You can do this using gdb or another debugger. Tell the debugger to stop when any exception is throw (in gdb the command is hilariously catch throw). Then you will see not only the type of the exception, but where exactly it is coming from.

Another idea is to comment out the catch (...) and let your runtime terminate your application and hopefully tell you more about the exception.

Once you figure out what the exception is, you should try to replace or augment it with something that does derive from std::exception. Having to catch (...) at all is not great.

If you use GCC or Clang you can also try __cxa_current_exception_type()->name() to get the name of the current exception type.

like image 32
John Zwinck Avatar answered Mar 07 '23 02:03

John Zwinck