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

前端 未结 5 595
太阳男子
太阳男子 2020-12-11 21:54

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

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


        
5条回答
  •  一个人的身影
    2020-12-11 22:19

    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.

提交回复
热议问题