use catch/throw in LORENE ID thorns to report file-open failures

Create issue
Issue #738 closed
Roland Haas created an issue

the LORENE classes Bin_NS/Bin_BH/Mag_NS do not check for errors in fopen and simply pass the returned file hanlde to fread. If one enters the wrong filename in parameter files this causes a segfault. The attached patches add a patch to ExternalLibraries/LORENE to check for the error condition and throw ios_base::failure(sterror(errno)) upon error. The ID thorns catch this exception.

My main questions is whether we are happy with this kind of error handling using C++ exceptions (which requires very little code change) or would rather have the LORENE classes themselves spit out the error message (and abort()). Notice that the error happens in a constructor so I cannot simply return an error code from the LORENE function.

Keyword:

Comments (4)

  1. Erik Schnetter
    • removed comment

    Using C++ exceptions should be fine. You may want to check that they are supported (by the compiler, and by Simfactory's options) on the relevant systems; some HPC systems are quite weird (e.g. Blue Gene/P does not support symbolic links).

    (I would have added a "#include <cctk.h>", and then called CCTK_WARN to abort.)

    Your patch disables a "rm -rf", probably unintentionally.

    The patch is fine, please apply.

  2. Log in to comment