So, I'm looking at the C++ reference for the try/catch block.
I see there are a few ways to capture an exception like so:
try {
f();
} catch (const std::overflow_error& e) {
// this executes if f() throws std::overflow_error (same type rule)
} catch (const std::runtime_error& e) {
// this executes if f() throws std::underflow_error (base class rule)
} catch (const std::exception& e) {
// this executes if f() throws std::logic_error (base class rule)
} catch (...) {
// this executes if f() throws std::string or int or any other unrelated type
}
I see in the following examples that you can capture the "e" data like so:
std::cout << e.what();
So my question boils down to this:
How do I get the exception data on the catch(...)
?
(Side question: is it even wise to use the catch(...)
?)