# Catching NonDeterministicException

**URL:** <https://community.temporal.io/t/catching-nondeterministicexception/5020>\
**Category:** Community Support\
**Tags:** java-sdk, general-impl\
**Created:** [June 20, 2022, 10:39pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020 "2022-06-20T22:39:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cgardens](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/cgardens/32/1746_2.png) [@cgardens](https://community.temporal.io/u/cgardens)\
**Post date:** [June 20, 2022, 10:39pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/1 "2022-06-20T22:39:30Z")

</div>

I’ve been bitten a couple of times by making changes to a workflow that caused a `NonDeterministicException`. I have a use case where when this is thrown, I just want the workflow to fail, so that I can trigger a new workflow with the same inputs on the new version. Basically the desired behavior is when `NonDeterministicException` just give up on the workflow.

Is there a kosher way of doing this? For example, can I catch `NonDeterministicException` and just mark it as a `NonRetryableException`?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [June 21, 2022, 7:42pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/2 "2022-06-21T19:42:53Z")

</div>

NonDeterministicException cannot be caught inside your workflow code, but  
you could set it to fail workflow execution via WorkflowImplementationOptions, for example:

```auto
WorkflowImplementationOptions options =
                WorkflowImplementationOptions.newBuilder()
                        .setFailWorkflowExceptionTypes(NonDeterministicException.class)
                        .build();
worker.registerWorkflowImplementationTypes(options, MyWorkflowImpl.class);

```

This should fail your workflow in case of NonDeterministicException.  
Imo still the default behavior of blocking workflow task allowing you to fix the issue (using versioning for example) might be a better approach than failing the workflow execution.

---

<div class="post-metadata">

**Author:** ![\_Elbek\_Khoshimjonov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/_elbek_khoshimjonov/32/3178_2.png) [@\_Elbek\_Khoshimjonov](https://community.temporal.io/u/_Elbek_Khoshimjonov)\
**Post date:** [January 25, 2024, 8:23pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/3 "2024-01-25T20:23:20Z")

</div>

> [@tihomir](#):
>
> WorkflowImplementationOptions

What would be the Golang equivalent for this? I could not find `worker.RegisterWorkflowImplementationTypes` or anything close.

And is there a way to restart the workflow if the `NonDeterministic` error happens?

---

<div class="post-metadata">

**Author:** ![\_Elbek\_Khoshimjonov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/_elbek_khoshimjonov/32/3178_2.png) [@\_Elbek\_Khoshimjonov](https://community.temporal.io/u/_Elbek_Khoshimjonov)\
**Post date:** [January 25, 2024, 8:38pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/4 "2024-01-25T20:38:59Z")

</div>

> [@tihomir](#):
>
> `WorkflowImplementationOptions`

Happy to add it if it is not there for go SDK!

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [January 28, 2024, 10:48am UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/5 "2024-01-28T10:48:51Z")

</div>

I think for Go you’d need to set panic policy in WorkerOptions currently, something like

```auto
workerOptions := worker.Options{
	// ...
	WorkflowPanicPolicy: worker.FailWorkflow,
}
w := worker.New(ctx, "myworkflow", workerOptions)

```

---

<div class="post-metadata">

**Author:** ![mvp](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/mvp/32/941_2.png) [@mvp](https://community.temporal.io/u/mvp)\
**Post date:** [February 7, 2024, 12:01pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/6 "2024-02-07T12:01:25Z")

</div>

Hi @tihomir ,

A `WorkflowPanicPolicy` that restarts workflows on nondeterministic error might be a good addition. Do you think that is something I could create a github issue for?

My use-case is this:  
All workflows that we write at my company are restartable. i.e, we maintain our own checkpoints so that when a workflow is restarted, it continues from where it left off. We tend not to use workflow versioning since that makes the workflow code hard to read. Hence, an option to automatically restart workflows (a fixed number of times) on nondeterministic error would be super helpful.

---

<div class="post-metadata">

**Author:** ![\_Elbek\_Khoshimjonov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/_elbek_khoshimjonov/32/3178_2.png) [@\_Elbek\_Khoshimjonov](https://community.temporal.io/u/_Elbek_Khoshimjonov)\
**Post date:** [February 8, 2024, 8:05pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/7 "2024-02-08T20:05:28Z")

</div>

@mvp We have a workaround without any changes to the temporal.  
With `WorkflowPanicPolicy` set to `worker.FailWorkflow`  
And `RetryPolicy` set to some value when starting a workflow allows us to restart the workflow when workflow encounters non-deterministic panics.

But there are a few caveats:

- Any panic will result in workflow restarting
- Any real errors returning from the workflow to terminate the workflow must be wrapped with `temporal.NewNonRetyableError`
- Workflow retry does not seem to replay this signals (which we want for our use case)

---

<div class="post-metadata">

**Author:** ![\_Elbek\_Khoshimjonov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/_elbek_khoshimjonov/32/3178_2.png) [@\_Elbek\_Khoshimjonov](https://community.temporal.io/u/_Elbek_Khoshimjonov)\
**Post date:** [February 9, 2024, 2:58pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/8 "2024-02-09T14:58:08Z")

</div>

@tihomir is there a way to achieve signal replay when the workflow retries?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [February 9, 2024, 6:41pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/9 "2024-02-09T18:41:12Z")

</div>

> [@mvp](#):
>
> A `WorkflowPanicPolicy` that restarts workflows on nondeterministic error might be a good addition. Do you think that is something I could create a github issue for?

This is already supported by specifying retry options for the workflow on start.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [February 9, 2024, 6:42pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/10 "2024-02-09T18:42:36Z")

</div>

> [@\_Elbek\_Khoshimjonov](#):
>
> @tihomir is there a way to achieve signal replay when the workflow retries?

File an issue to add “reset” on the panic option.

---

<div class="post-metadata">

**Author:** ![Jeeyoung\_Kim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/jeeyoung_kim/32/7564_2.png) [@Jeeyoung\_Kim](https://community.temporal.io/u/Jeeyoung_Kim)\
**Post date:** [July 27, 2025, 4:20am UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/11 "2025-07-27T04:20:02Z")

</div>

Commenting on this thread because I think this is the closest thing;

Is there an equivalent option for TypeScript? Especially for testing?

One thing I noticed - and correct me if I’m wrong, is that the ergonomics of the TypeScript workflow testing is pretty bad on failures. Specifically, if it fails for these “system” reasons - either missing activity definition or an uncaught exception in the workflow code, then the workflow is stuck in an infinite retry loop, so the error surfaces in timing out.

I would rather want these failures to fail immediately. I believe that go’s WorkflowPanicPolicy would handle the case I describe, but I don’t think there’s a similar option on the TypeScript side.

Thanks!

---

<div class="post-metadata">

**Author:** ![Kate\_Bultman](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/kate_bultman/32/7026_2.png) [@Kate\_Bultman](https://community.temporal.io/u/Kate_Bultman)\
**Post date:** [August 11, 2025, 3:11pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/12 "2025-08-11T15:11:49Z")

</div>

+1 also need to know if this is doable in typescript, I do not see `WorkflowPanicPolicy` or `WorkflowImplementationOptions`

@maxim @tihomir

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [August 11, 2025, 4:42pm UTC](https://community.temporal.io/t/catching-nondeterministicexception/5020/13 "2025-08-11T16:42:59Z")

</div>

Hi,

you can follow this issue [[Feature Request] Configurable workflow failure exception types · Issue #1358 · temporalio/sdk-typescript · GitHub](https://github.com/temporalio/sdk-typescript/issues/1358)

the sdk team is already working on it [[WIP] feat(workflow): Add support for failing workflow execution on some error types by mjameswh · Pull Request #1732 · temporalio/sdk-typescript · GitHub](https://github.com/temporalio/sdk-typescript/pull/1732)

Antonio
