Custom error handler

You can define your own custom error handler by overriding the onError() function of the simulation experiment

The handler will be invoked every time an exception is thrown in any action of transitions, events, dynamic events, etc. 

If this function returns true, the model continues its execution, otherwise if it returns false, the model is terminated.

 To define the custom error handler

  1. Add Function  on the diagram of the simulation experiment. 

  2. Name the function onError.
  3. In the Arguments section of the function's properties, add the parameter of Type java.lang.Throwable. The Name of the argument can be arbitrary, say, err.
  4. In the Function body, define the error handler code (using Java).
    For example, we want to output the error information in AnyLogic Console and then automatically shut down the model. To do this, write there:

    traceln("An error occurred: " + err);
    close();