Howto - handle exceptions in a Mendix microflow

I received a question recently about the ability to handle errors in custom Java actions, for example for calling a REST service. The following illustrates how you can handle Exceptions thrown in Java actions.

define an error handler

On microflow actions you can set an error handler, as you can see in this screenshot, where an error handler is defined for a java action.

Set error handler on a microflow action

Handle the error

Now you can define actions that need to be performed in case of an error. Usually you'll want to log the error. In case of service calls, you'll often want to compensate for anything that you did before the exception.

The following screenshot shows that the error is logged, and then some error handling is executed based on the type of error.

Handling the error in a microflow

Logging the error

The following screenshot shows you how you can log the error. It is surprising how often this is forgotten, resulting in long debugging sessions in production, where nobody really understand why the program is silently failing.

Logging the exception

Errorhandling by type

The last screenshot illustrates how you can test what kind of error occurred. You can use this to handle different errors differently.

Split on exception type