Skip to content

Commit

Permalink
Suppress duplicate error message if simulation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Nov 12, 2016
1 parent 0665436 commit 47e1846
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
42 changes: 16 additions & 26 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -9803,11 +9803,10 @@ template equationString(SimEqSystem eq, Context context, Text &varDecls, SimCode
_algLoopSolver<%ls.index%>->solve();
_callType = calltype;
}
catch(ModelicaSimulationError& ex)
catch (ModelicaSimulationError& ex)
{

string error = add_error_info("Nonlinear solver <%ls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
string error = add_error_info("Nonlinear solver <%ls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM, error);
}
>>
else
Expand Down Expand Up @@ -9854,11 +9853,10 @@ template equationString(SimEqSystem eq, Context context, Text &varDecls, SimCode
_algLoopSolver<%ls.index%>->solve();
_callType = calltype;
}
catch(ModelicaSimulationError& ex)
catch (ModelicaSimulationError& ex)
{
string error = add_error_info("Nonlinear solver <%ls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);

string error = add_error_info("Nonlinear solver <%ls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}
}
>>
Expand Down Expand Up @@ -9886,9 +9884,8 @@ template equationString(SimEqSystem eq, Context context, Text &varDecls, SimCode
}
catch(ModelicaSimulationError& ex)
{

string error = add_error_info("Nonlinear solver <%nls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
string error = add_error_info("Nonlinear solver <%nls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}
>>
else
Expand Down Expand Up @@ -9937,9 +9934,8 @@ template equationString(SimEqSystem eq, Context context, Text &varDecls, SimCode
}
catch(ModelicaSimulationError& ex)
{
string error = add_error_info("Nonlinear solver <%nls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);

string error = add_error_info("Nonlinear solver <%nls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}
}
>>
Expand Down Expand Up @@ -11484,8 +11480,8 @@ template equationLinearOrNonLinear(SimEqSystem eq, Context context,Text &varDecl
}
catch(ModelicaSimulationError& ex)
{
string error = add_error_info("Nonlinear solver stopped",ex.what(),ex.getErrorID(),_simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
string error = add_error_info("Nonlinear solver", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}
>>
else
Expand Down Expand Up @@ -11535,13 +11531,10 @@ template equationLinearOrNonLinear(SimEqSystem eq, Context context,Text &varDecl
}
catch(ModelicaSimulationError& ex)
{
string error = add_error_info("Nonlinear solver <%ls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
string error = add_error_info("Nonlinear solver <%ls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}

}


>>
end match

Expand All @@ -11564,8 +11557,8 @@ template equationLinearOrNonLinear(SimEqSystem eq, Context context,Text &varDecl
}
catch(ModelicaSimulationError& ex)
{
string error = add_error_info("Nonlinear solver <%nls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
string error = add_error_info("Nonlinear solver <%nls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}
>>
else
Expand Down Expand Up @@ -11615,13 +11608,10 @@ template equationLinearOrNonLinear(SimEqSystem eq, Context context,Text &varDecl
}
catch(ModelicaSimulationError& ex)
{
string error = add_error_info("Nonlinear solver <%nls.index%> stopped",ex.what(),ex.getErrorID(),_simTime);
string error = add_error_info("Nonlinear solver <%nls.index%>", ex.what(), ex.getErrorID(), _simTime);
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,error);
}

}


>>
end match
end match
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -251,7 +251,7 @@ void SimController::Start(SimSettings simsettings, string modelKey)
catch(ModelicaSimulationError & ex)
{
string error = add_error_info(string("Simulation failed for ") + simsettings.outputfile_name,ex.what(),ex.getErrorID());
throw ModelicaSimulationError(SIMMANAGER,error);
throw ModelicaSimulationError(SIMMANAGER, error, "", ex.isSuppressed());
}
}

Expand Down
11 changes: 6 additions & 5 deletions SimulationRuntime/cpp/Core/SimController/SimManager.cpp
Expand Up @@ -277,12 +277,13 @@ void SimManager::runSimulation()
}
catch (std::exception & ex)
{
LOGGER_WRITE("SimManager: Simulation finish with errors at t = " + to_string(_tEnd), LC_SOLV, LL_ERROR);
LOGGER_WRITE("SimManager: Simulation stopped with errors before t = " +
to_string(_tEnd), LC_SOLV, LL_ERROR);
LOGGER_WRITE("SimManager: " + string(ex.what()), LC_SOLV, LL_ERROR);
writeProperties();

LOGGER_WRITE("SimManager: Error = " + string(ex.what()), LC_SOLV, LL_ERROR);
//ex << error_id(SIMMANAGER);
throw;
// rethrow with suppress depending on logger setting to not appear twice
throw ModelicaSimulationError(SIMMANAGER, ex.what(), "",
LOGGER_IS_SET(LC_SOLV, LL_ERROR));
}
#ifdef RUNTIME_PROFILING
if (MeasureTime::getInstance() != NULL)
Expand Down
Expand Up @@ -35,7 +35,7 @@ class ModelicaSimulationError : public runtime_error
* @param suppress Set to true if the error should not appear on std::err and std::out.
*/
ModelicaSimulationError(SIMULATION_ERROR error_id, const string& error_info, string description = "", bool suppress = false)
: runtime_error("simulation error message: " + error_info + (description.size() > 0 ? "\n" + description : ""))
: runtime_error(error_info + (description.size() > 0 ? "\n" + description : ""))
, _error_id(error_id)
, _suppress(suppress)
{
Expand Down

0 comments on commit 47e1846

Please sign in to comment.