fix(java): wrap bare rethrows of checked exceptions - #62
Merged
Conversation
`throw e` inside a `catch (Exception e)` block was emitted verbatim, but java.lang.Exception is checked and the CompletableFuture lambdas that the transpiled ccxt method bodies live in cannot declare `throws` - javac fails with "unreported exception Exception". First triggered by the mexc ws authenticate fix (ccxt/ccxt#29392), whose java emission broke the ccxt java build. The identifier branch now emits a conditional wrap: throw (e instanceof RuntimeException ? (RuntimeException)e : new RuntimeException(e)); which keeps unchecked exceptions (all ccxt errors extend RuntimeException) rethrown with their identity intact and wraps genuinely checked ones with the original as the cause. Verified against ccxt: regenerated MexcCore.java compiles the construct; the previous emission reproduces the javac error.
kroitor
added a commit
to ccxt/ccxt
that referenced
this pull request
Jul 31, 2026
Pins ast-transpiler to current master (35154c4, parent: the #62 squash), picking up ccxt/ast-transpiler#62: bare rethrows of checked exceptions now emit as a conditional RuntimeException wrap, fixing the java.yml Build Project failure introduced when the mexc ws authenticate fix (#29392) became the first `throw e` transpiled to Java. ccxt error types extend RuntimeException and keep their identity through the wrap. Verified locally with the fix-equivalent dist: MexcCore.java emits the compilable form, isolated javac proof both ways, C#/PHP/Python legs clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What broke
printThrowStatement's Identifier branch emits a bare rethrow (throw e) verbatim. In the transpiled ccxt Java, method bodies live insideCompletableFuturelambdas which cannot declarethrows, so rethrowing the caught (checked)java.lang.Exceptionfails compilation:First real-world trigger: the mexc ws
authenticatefix (ccxt/ccxt#29392) — the first bare rethrow ever transpiled to Java in ccxt — whose auto-committed emission broke ccxt'sjava.ymlBuild Project step (failing run).Fix
Emit a conditional wrap in the Identifier branch:
RuntimeException— rethrow with identity intact, so upstreamcatchdispatch on ccxt exception types is unaffectedcauseVerified against ccxt
java/lib/.../pro/MexcCore.java→ emits the conditional form at the previously-broken sitesupplyAsynclambda; the previous emission reproduces the exact CI error