try {
activity1.function1();
} catch (SomeCheckedException e) {
log.info("Exception thrown from activity 1");
// Terminate the workflow
}
activity2.function2();
There are two activities. Suppose some checked exception, “SomeCheckedException” is thrown from activity1, I want to catch this in workflow and do some custom logic in the catch block. I tried throwing two exceptions from activity1:
a) SomeCheckedException1, which is not set in the activity retry options setDoNotRetry
b) SomeCheckedException2, which is set in the activity retry options setDoNotRetry
In either of the cases, the execution is not reaching the catch block.
What can be done so that I can execute some custom logic in the catch block?
What is the proper way of terminating the workflow, so that activity2.function2() is not invoked in case activity1.function1() throws some exception?
Is there any recommended way of throwing exceptions from activities?
a) SomeCheckedException1, which is not set in the activity retry options setDoNotRetry
Activity executions will retry based on the retry options, if you don’t limit the number of retries or set schedule_to_close, the activity will retry indefinitely if this exception is thrown (while the workflow is in the open state.)
b) SomeCheckedException2, which is set in the activity retry options setDoNotRetry
If the activity fails, with a non-retryable failure, it will throw an ActivityFailure which is what you want to catch. See this example. You can get the initial error with ((ApplicationFailure) af.getCause()).getType())
What can be done so that I can execute some custom logic in the catch block
I think I answered this above; let me know if you have questions.
What is the proper way of terminating the workflow, so that activity2.function2() is not invoked in case activity1.function1() throws some exception?
one way, in your catch block you can rethrow the exception, or don’t catch it if you don’t have to run any extra step after function1 fails.
Is there any recommended way of throwing exceptions from activities?
I guess it depends on the use-case.
If you want to throw a non-retryable exception, you can do what you are already doing (set retryOptions.setDoNotRetry ) or throw ApplicationFailure.newNonRetryableFailure(...) from your activity code.