Runtime Errors

Various errors may occur during the model execution. Runtime errors can be of two types:

You can throw runtime error and terminate model execution as a reaction to different undesirable occurrences.

Java exceptions

Java code written by the user may contain unintentional errors like computational errors in expressions specified by the user (division by zero, or square root of a negative value), accessing null pointer and so on. Such errors are detected by Java runtime environment. If such an error occurs, Java throws an exception.

AnyLogic catches all exceptions. If an exception occurs, AnyLogic stops the model, notifies the user with a message box and dumps the exception to the global log. You can examine the log to find out where there is a bug.

Simulation errors

Simulation errors are logical errors of model execution. For example, if a statechart is unable to exit a branch because all exiting transitions are closed, it is a simulation error. Simulation errors are detected by AnyLogic rather than by Java runtime environment. If a simulation error occurs, AnyLogic stops the model and notifies the user with an error message.

Throwing runtime errors

You can debug your model at runtime by throwing runtime errors as a reaction to undesirable occurrences using the function error() of the class Engine. The error() function throws runtime exception to the simulation engine.