How can I catch the exception related to exceeding the workflow history size or count limit in Java?

Hi All,

I am executing an Async Workflow using the workflow client as shown below.
WorkflowClient.start(wflow::execute, flowContext);
When the workflow history size or count exceeds the limit, I am unable to catch this exception inside the Java code. The workflow gets terminated, and the status is updated as terminated.

How can I catch the exception related to exceeding the workflow history size or count limit in Java?

Hi @Aswath_Murugan

you can not, the workflow is terminated by the server which does not allow you to react in workflow code.

What you should do instead is to watch periodically the event history length, in your workflow code, and https://docs.temporal.io/workflows#continue-as-new if the same reach certain value. We don’t recommend going above 10k

something like:

 if(Workflow.getInfo().getHistoryLength() > 10_000){
        Workflow.continueAsNew(data);
 }

If you want to share the use-case we can help advising with the implementation,

Regards,
Antonio