public class MyException extends RuntimeException {
private Integer data;
public MyException(Integer data) { this.data = data; }
public Integer getData() { return data; }
}
public class MyActivityImpl implements MyActivity {
@Override
public void doSomething() {
if (someSpecificCondition) throw new MyException(1234);
...
}
}
That is called from the workflow
@WorkflowInterface
public interface MyWorkflow {
@WorkflowMethod
void myMethod();
}
public class MyWorkflowImpl implements MyWorkflow {
private final MyActivity myActivity;
...
@Override
public void myMethod() {
try {
myActivity.doSomething();
}
catch (TemporalException e) {
// Handle exception when retries are exhausted
// using ((MyException)...).getData()
}
}
}
We are now needing to retrieve the information passed to the exception, but at the catch every exception in the stack is an ApplicationFailure containing the exception type and the message, but not the data inside the exception. So, we cannot call getData to retrieve the specific information.
Is there any way to propagate the custom exception, or include it as part of the ApplicationFailure? Should we completely reconsider that approach?
The exception we are throwing is unchecked, so I believe there is no need to wrap it. The issue is we need that custom data inside the exception, which is not a string message, to decide how we want to handle it.
I’ve updated the original message a bit to make it clearer.
To pass a custom data through an ApplicationFailure from the activity code explicitly. The ApplicationFailure factory method accepts the details arguments that can be accessed through ApplicationFailure.getDetails.
I am trying to throw a custom exception(i.e ApplicationException internally extending RuntimeException) and the same is wrapped using Activity.wrap(). But when the same is caught in Workflow code as part of catch block, I am unable to get the details of my custom exception. Can you please suggest on the same.
@tihomir I am looking for custom fields populated as part of the exception. I have a list of ValidationErrors populated as part of the custom exception(i.e BusinessException class), so trying to read the same in catch block.
I think (could be wrong) what’s meant is to throw ApplicationFailure from your activity code as you can define custom details, for example:
throw ApplicationFailure.newFailure("My Custom Failure...", "MyCustomFailure",
new Customer("John"), new Customer("Marry"));
where “MyCustomFailure” is the failure type and the two customer objects are details that you want to be able retrieve in your workflow code where you catch the failure, for example:
Thanks @tihomir . Will try out this approach. But will this approach have any impact on the exception types that we define as doNotRetry in activity retry options?