Skip to content

Commit

Permalink
Log errors during initialization and asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Nov 14, 2016
1 parent f2e948c commit b6a7a6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
30 changes: 13 additions & 17 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -2719,20 +2719,18 @@ template calcHelperMainfile(SimCode simCode ,Text& extraFuncs,Text& extraFuncsDe
#include <Core/System/DiscreteEvents.h>
#include <Core/System/EventHandling.h>
#include <Core/DataExchange/XmlPropertyReader.h>

#include <Core/Utils/extension/logger.hpp>

#include "OMCpp<%fileNamePrefix%>Types.h"
#include "OMCpp<%fileNamePrefix%>Functions.h"
#include "OMCpp<%fileNamePrefix%>.h"


#include "OMCpp<%fileNamePrefix%>Jacobian.h"
#include "OMCpp<%fileNamePrefix%>Mixed.h"
#include "OMCpp<%fileNamePrefix%>StateSelection.h"
#include "OMCpp<%fileNamePrefix%>WriteOutput.h"
#include "OMCpp<%fileNamePrefix%>Initialize.h"


#include "OMCpp<%fileNamePrefix%>AlgLoopMain.cpp"
#include "OMCpp<%fileNamePrefix%>FactoryExport.cpp"
#include "OMCpp<%fileNamePrefix%>Mixed.cpp"
Expand Down Expand Up @@ -11708,27 +11706,25 @@ template assertCommon(Exp condition, Exp message,Exp level, Context context, Tex

<%if msgVar then
<<
<%preExpCond%>
if(!<%condVar%>)
{
<%preExpMsg%>
<%match level case ENUM_LITERAL(index=2)
then 'cerr <<"Warning: " << <%msgVar%>;'
else
'throw ModelicaSimulationError(MODEL_EQ_SYSTEM,<%msgVar%>);'
%>

}
<%preExpCond%>
if (!<%condVar%>)
{
<%preExpMsg%>
<%match level case ENUM_LITERAL(index=2)
then 'LOGGER_WRITE(<%msgVar%>, LC_MODEL, LL_WARNING);'
else 'throw ModelicaSimulationError(MODEL_EQ_SYSTEM, <%msgVar%>);'
%>
}
>>
else
<<
if(!<%condVar%>)
if (!<%condVar%>)
{
<%preExpCond%>
<%preExpMsg%>
<%match level case ENUM_LITERAL(index=2)
then 'cerr <<"Warning: >Assert in model equation";'
else 'throw ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM);'
then 'LOGGER_WRITE("Assert in model equation", LC_MODEL, LL_WARNING);'
else 'throw ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM);'
%>
}
>>
Expand Down
9 changes: 6 additions & 3 deletions SimulationRuntime/cpp/Core/SimController/SimManager.cpp
Expand Up @@ -124,8 +124,11 @@ void SimManager::initialize()
}
catch (std::exception& ex)
{
LOGGER_WRITE("SimManager: Could not initialize system", LC_INIT, LL_ERROR);
LOGGER_WRITE("SimManager: " + string(ex.what()), LC_INIT, LL_ERROR);
//ex << error_id(SIMMANAGER);
throw ModelicaSimulationError(SIMMANAGER,"Could not initialize system.",string(ex.what()),false);
throw ModelicaSimulationError(SIMMANAGER, "Could not initialize system",
string(ex.what()), LOGGER_IS_SET(LC_INIT, LL_ERROR));
}

if (_timeevent_system)
Expand Down Expand Up @@ -282,8 +285,8 @@ void SimManager::runSimulation()
LOGGER_WRITE("SimManager: " + string(ex.what()), LC_SOLVER, LL_ERROR);
writeProperties();
// rethrow with suppress depending on logger setting to not appear twice
throw ModelicaSimulationError(SIMMANAGER, ex.what(), "",
LOGGER_IS_SET(LC_SOLVER, LL_ERROR));
throw ModelicaSimulationError(SIMMANAGER, "Simulation stopped with errors before t = " + to_string(_tEnd),
string(ex.what()), LOGGER_IS_SET(LC_SOLVER, LL_ERROR));
}
#ifdef RUNTIME_PROFILING
if (MeasureTime::getInstance() != NULL)
Expand Down

0 comments on commit b6a7a6d

Please sign in to comment.