Call finalizeForCommandLine even if an exception is thrown so that it is
OK to call runAsMainSingleModule again. This allows this (and the calling
runAsMain as e.g. used in the template) be called from some framework which
doesn't reset globals.
Change-Id: I9eff770e06feef90f99ec0445bd294816f8b6a0a
g_commandLineContext.reset();
}
g_commandLineContext.reset();
}
+int processExceptionAtExitForCommandLine(const std::exception &ex)
+{
+ int rc = processExceptionAtExit(ex); //Currently this aborts for GMX_LIB_MPI
+ finalizeForCommandLine(); //thus this MPI_Finalize doesn't matter
+ return rc;
+}
+
int runCommandLineModule(int argc, char *argv[],
CommandLineModuleInterface *module)
{
int runCommandLineModule(int argc, char *argv[],
CommandLineModuleInterface *module)
{
* \ingroup module_commandline
*/
void finalizeForCommandLine();
* \ingroup module_commandline
*/
void finalizeForCommandLine();
+/*! \brief
+ * Handles an exception and deinitializes after initForCommandLine.
+ *
+ * \param[in] ex Exception that is the cause for terminating the program.
+ * \returns Return code to return from main().
+ *
+ * This method should be called as the last thing before terminating the
+ * program because of an exception. See processExceptionAtExit() for details.
+ * Additionally this method undoes the work done by initForCommandLine.
+ *
+ * Does not throw.
+ */
+int processExceptionAtExitForCommandLine(const std::exception &ex);
/*! \brief
* Implements a main() method that runs a single module.
*
/*! \brief
* Implements a main() method that runs a single module.
*
catch (const std::exception &ex)
{
printFatalErrorMessage(stderr, ex);
catch (const std::exception &ex)
{
printFatalErrorMessage(stderr, ex);
- return processExceptionAtExit(ex);
+ return processExceptionAtExitForCommandLine(ex);
catch (const std::exception &ex)
{
gmx::printFatalErrorMessage(stderr, ex);
catch (const std::exception &ex)
{
gmx::printFatalErrorMessage(stderr, ex);
- return gmx::processExceptionAtExit(ex);
+ return gmx::processExceptionAtExitForCommandLine(ex);
catch (const std::exception &ex)
{
gmx::printFatalErrorMessage(stderr, ex);
catch (const std::exception &ex)
{
gmx::printFatalErrorMessage(stderr, ex);
- return gmx::processExceptionAtExit(ex);
+ return gmx::processExceptionAtExitForCommandLine(ex);
catch (const std::exception &ex)
{
printFatalErrorMessage(stderr, ex);
catch (const std::exception &ex)
{
printFatalErrorMessage(stderr, ex);
- std::exit(processExceptionAtExit(ex));
+ std::exit(processExceptionAtExitForCommandLine(ex));