AnyLogic
Expand
Font size

Error signaling functions

Function Description
RuntimeException error(String errorText) Signals an error during the model run by throwing a RuntimeException with the given text: errorText preceded by the agent full name. This function never returns a value, it throws runtime exception by itself. The return type is defined for the cases when you want to use the following form of call: throw error("my message");

errorText — the text describing the error that will be displayed
RuntimeException error(Throwable cause, String errorText) Signals an error during the model run by throwing a RuntimeException with the given text: errorText. This function never returns a value, it throws runtime exception by itself. The return type is defined for the cases when you want to use the following form of call: throw error("my message");

cause — the cause (which will be saved for more detailed message), may be null
errorText — the text describing the error that will be displayed
RuntimeException error(String errorTextFormat, Object... args) The same as error(String) but allows error format syntax like in String.format(String, Object...) function.
RuntimeException error(Throwable cause, String errorTextFormat, Object... args) The same as error(String) but allows error format syntax like in String.format(String, Object...) function.

cause — the cause (which will be saved for more detailed message), may be null
RuntimeException errorInModel(String errorText) Signals a model logic error during the model run by throwing a ModelException with specified errorText preceded by the agent full name. This function never returns a value, it throws runtime exception by itself. The return type is defined for the cases when you want to use the following form of call: throw errorInModel("my message");
This function differs from error() in the way of displaying error message: model logic errors are "softer" than other errors, they happen in the models and signal the modeler that the model might need some parameter adjustments. Examples: "agent was unable to leave the flowchart block because the following block was busy", "insufficient capacity of storage", etc.

errorText — the text describing the error that will be displayed
RuntimeException errorInModel(Throwable cause, String errorText) Signals a model logic error during the model run by throwing a ModelException with specified errorText preceded by the agent full name. This function never returns a value, it throws runtime exception by itself. The return type is defined for the cases when you want to use the following form of call: throw errorInModel("my message");
This function differs from error() in the way of displaying error message: model logic errors are "softer" than other errors, they happen in the models and signal the modeler that the model might need some parameter adjustments. Examples: "agent was unable to leave the flowchart block because the following block was busy", "insufficient capacity of storage", etc.

cause — the cause (which will be saved for more detailed message), may be null
errorText — the text describing the error that will be displayed
RuntimeException errorInModel(String errorTextFormat, Object... args) The same as errorInModel(String) but allows error format syntax like in String.format(String, Object...) function.
RuntimeException errorInModel(Throwable cause, String errorTextFormat, Object... args) The same as errorInModel(String) but allows error format syntax like in String.format(String, Object...) function.

cause — the cause (which will be saved for more detailed message), may be null
RuntimeException warning(String warningText) Signals a warning during the model run with warningText preceded by the agent full name. Warnings may be turned off in the AnyLogic preferences (runtime section) or by API: AnyLogicRuntimePreferences.setEnableWarnings(boolean).
This function checks against numerous warnings output:
  • In case of multiple warnings having equal warningText, only the first 10 of them are displayed.
  • When more than 1000 warnings having different warningText occur, all the subsequent warnings (including new occurrences of those in the first 1000) will stop displaying.
  • Be careful with using dynamically changing warningText (e.g. listing names of agents), it could be better to use warning(String, Object...).

warningText — the warning text that will be displayed
RuntimeException warning(String warningTextFormat, Object... args) Signals a warning during the model run with warningTextFormat preceded by the agent full name. The function allows warning format syntax like in String.format(String, Object...) method. Warnings may be turned off in the AnyLogic preferences (runtime section) or by API: AnyLogicRuntimePreferences.setEnableWarnings(boolean).
This function checks against numerous warnings output:
  • In case of multiple warnings having equal warningTextFormat, only the first 10 of them are displayed.
  • It is safe to raise numerous warnings with equal format string (which defines the warning type) but varying args - AnyLogic will take care to display only 10 first warnings of each warning type.
  • When more than 1000 warnings having different warningTextFormat occur, all the subsequent warnings (including new occurrences of those in the first 1000) will stop displaying.
  • Be careful with using dynamically changing warningText (e.g. listing names of agents), use args instead.
How can we improve this article?