Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • dumux dumux
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 100
    • Issues 100
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 87
    • Merge requests 87
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • dumux-repositoriesdumux-repositories
  • dumuxdumux
  • Issues
  • #915
Closed
Open
Issue created Aug 04, 2020 by Timo Koch@timokOwner

[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 a Dune::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.

Assignee
Assign to
Time tracking