1

In C++, we can get the exception information through catch(bad_cast& ex), then output the content of ex.what()

try{
     //…
}catch(std::bad_alloc& e)
{
    cout << “Catch bad alloc exception ” << e.what() << endl;
}
catch(std::bad_cast& e)
{
    cout << “Catch bad alloc exception ” << e.what() << endl;
}
catch(std::bad_exception& e)
{
    cout << “Catch bad alloc exception ” << e.what() << endl;
}
// catch more exception types here
// … 
catch(...)
{
    // how to get the content of unknown exception?
}

How to get the exception information from catch(...)?

zangw
  • 43,869
  • 19
  • 177
  • 214

1 Answers1

0

It's not something the language by itself can do.

... literally means "anything".

Which operations can you safely do on the "anything" ? You need in any case a type to check for. And that's noting more what you already did.

Emilio Garavaglia
  • 20,229
  • 2
  • 46
  • 63