[test][cleanup] Remove or reduce exception handlers
We usually have a list of exception handlers like this at the end of each main file
catch (Dumux::ParameterException &e)
{
std::cerr << std::endl << e << " ---> Abort!" << std::endl;
return 1;
}
catch (Dune::DGFException & e)
{
std::cerr << "DGF exception thrown (" << e <<
"). Most likely, the DGF file name is wrong "
"or the DGF file is corrupted, "
"e.g. missing hash at end of file or wrong number (dimensions) of entries."
<< " ---> Abort!" << std::endl;
return 2;
}
catch (Dune::Exception &e)
{
std::cerr << "Dune reported error: " << e << " ---> Abort!" << std::endl;
return 3;
}
catch (...)
{
std::cerr << "Unknown exception thrown! ---> Abort!" << std::endl;
return 4;
}
Small cleanup point:
- Catch all exceptions as
const&
Actual discussion points:
- The default terminate handler usually provides the exception message as well so manually catching exception is not necessary
- In case of the
Dune::DGFException
we actually add more information so that is a sensible use of the exception handler. However not every test will have the chance to throw aDune::DGFException
because not every test uses DGF mesh files. - In the other cases we just print the exception message which is what the default handler does anyway on most system AFAIK
- Catching
(...)
suppresses the exception message completely. This is a code smell. When such an exception occurs you have to manually remove the line to be able to read the exception message.
Suggestions:
- Try what is printed when we remove exception handlers completely (probably we don't need handlers at all for tests)
- Think about how to reduce handlers to a minimum
- Remove default catch case
(...)
Note: These comments are specifically for tests. If you have some Dumux application you might want to add exception handlers to gracefully exit out of an exception situation.