Handle activity failure exceptions in workflows

Hi Team,
I have a workflow with 100s of activities,some sequential and some parallel.
How to I catch exception in such a scenario?
Do I need to put try/catch in each sequential activity?
can you please tell me if there is any better way to handle it?

Also, in case of parallel activites, I want to continue my workflow if some activities fail.How do I handle exception in parallel activity case?
Thanks in advance.

1 Like

Workflow code handles exceptions exactly the same way as any other Java code. You handle exceptions according to your business logic and can use various programming techniques to avoid code duplication.

In the majority of cases intermittent activity errors are handled by automatic retries according to a retry options passed to the activity. So workflow code doesn’t need to handle them at all.

If you want to continue workflow execution on non intermittent activity failure then try-catch is the right approach.

If you need to surround a lot of activities with try-catch use the standard Java programming techniques to reduce the code duplication. For example:

  public static <T> T ignoreException(Supplier<T> function, T defaultValue) {
    try {
      return function.get();
    } catch (Exception e) {
      return defaultValue;
    }
  }

Can be used as

String result = ignoreException(() -> activities.activity1(arg), "Whatever");

If you want to get really fancy then you can create your own dynamic interceptor which uses your custom annotations to mark activities that have to ignore their exceptions.

1 Like