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.