I have a Modelica model that calls an external function. If the time step is too large, often the external C++ code throws an exception.
It seems like the proper thing to do in response would be to reduce the time step and try again. Is there a way to reduce the timestep in response to an exception?
There is no direct standardized way, but you can catch the exception and either return it as an error flag to Modelica and use assert
, or use ModelicaError
in a C-wrapper (using ModelicaError in the catch-part in C++ might be possible).
The specification states that after a failed assertion (or call of ModelicaError) the simulation may continue with another evaluation e.g., with a shorter step-size, or by changing the values of iteration variables.