I have some program and everytime I run it, it throws exception and I don't know how to check what exactly it throws, so my question is, is it possible to catch exception and print it (I found rows which throws exception) thanks in advance
Retrying your task. The main characteristic of an unknown exception is you can't specifically handle it. Often you won't know why and when it happened and how to work around it. Retrying your task a specific number of times is a useful technique to deal with sporadically unknown exceptions.
start a debugger and place a breakpoint in the exceptions constructor, and see from where it is being called. the caling function is probably something like __throw(). afterwards, start the debugger again with the program you want to investigate as debuggee.
If it derives from std::exception
you can catch by reference:
try { // code that could cause exception } catch (const std::exception &exc) { // catch anything thrown within try block that derives from std::exception std::cerr << exc.what(); }
But if the exception is some class that has is not derived from std::exception
, you will have to know ahead of time it's type (i.e. should you catch std::string
or some_library_exception_base
).
You can do a catch all:
try { } catch (...) { }
but then you can't do anything with the exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With