I am new to C++ and wondering how I could catch all possible errors that could happen in my program during run-time. This is for debugging reasons only. To solve possible errors, I would like to have a look at them first.
This would be my idea of how to catch possible errors in a program. I do not throw exceptions, but would like to catch possible errors directly.
#include <iostream>
#include <exception>
#include <stdexcept>
int doBadStuf(int i)
{
// go out of bounce, or make other mistakes
return 10 / i;
}
int main()
{
try
{
int i = doBadStuf(0);
}
catch (std::exception &e)
{
std::cerr << e.what() << '\n';
}
catch (...)
{
std::cerr << "something else";
}
}