Skip to content

Add Java SDK error-handling best practices page - #5050

Merged
Duncanma merged 5 commits into
mainfrom
duncanma/java-error-handling
Aug 7, 2026
Merged

Add Java SDK error-handling best practices page#5050
Duncanma merged 5 commits into
mainfrom
duncanma/java-error-handling

Conversation

@Duncanma

@Duncanma Duncanma commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds docs/develop/java/best-practices/error-handling.mdx — Java was the one major SDK missing the error-handling page that Go, Python, .NET, and Ruby already have.

Closes #5013
Closes #4006

The page covers:

  • Catching Exception, never Throwable or Error — with the reasoning (DestroyWorkflowThreadError, UnsupportedVersion) and a catch-decision order for Workflow/Update/Signal code
  • The catch (Throwable t) swallow-all anti-pattern, spelled out with the three concrete failure modes it causes
  • Wrapping checked exceptions with Workflow.wrap() / Activity.wrap() instead of adding them to method signatures, including direct answers to "do I need to wrap what I throw" and "do I need to re-wrap after unwrapping"
  • Reading a failure's cause chain (ActivityFailureChildWorkflowFailureApplicationFailure), including the getMessage() vs getOriginalMessage() gotcha and matching on getType() instead of instanceof
  • Handling Activity/Child Workflow failures and cancellation, linking out to the existing Non-Retryable Errors and Saga Pattern design-pattern pages rather than duplicating them
  • Centralizing failure conversion in a WorkerInterceptor

Also wires the page into sidebars.js and the best-practices index, and cross-links it from the cancellation page (the one spot #5013 called out as having an indirect, one-sentence mention of the catch-Throwable rule today).

Notes to reviewers

Every code-level claim is verified against sdk-java source (CheckedExceptionWrapper, the failure/* classes, DestroyWorkflowThreadError, UnsupportedVersion), the official HelloException and bookingsaga samples, and an internal best-practices writeup on Java error handling — not just the community forum post cited in #5013.

Scope note: the source material I checked goes considerably deeper (retry classification by HTTP/gRPC status code, cross-attempt error-context accumulation via heartbeats, a generic exception↔ApplicationFailure converter pattern, full Saga mechanics). I kept those out of this page to match the depth of the sibling Go/.NET/Ruby pages and avoid duplicating /design-patterns/non-retryable-errors and /design-patterns/saga-pattern — happy to split any of that into follow-up pages if you'd rather have it documented too.

┆Attachments: EDU-6902 Add Java SDK error-handling best practices page

Java was missing the error-handling page that Go, Python, .NET, and Ruby
already have. Covers catching Exception (never Throwable/Error), wrapping
checked exceptions with Workflow.wrap()/Activity.wrap(), reading a failure's
cause chain, and centralizing failure conversion in a Worker Interceptor.
@Duncanma
Duncanma requested a review from a team as a code owner August 6, 2026 18:46
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
temporal-documentation Ready Ready Preview Aug 7, 2026 9:51pm

Request Review

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📖 Docs PR preview links

@Duncanma
Duncanma merged commit 32ed254 into main Aug 7, 2026
15 checks passed
@Duncanma
Duncanma deleted the duncanma/java-error-handling branch August 7, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document that Workflow code must only catch Exception, never Throwable or Error Exception Wrapping in Java

2 participants