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(...)?

1
  • 1
    In short: You can't reliably. Commented Sep 18, 2014 at 7:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.