-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross-target exception handling #9124
Cross-target exception handling #9124
Conversation
This PR is ready for review \o/ @hughsando @ncannasse @Simn please, check the changes related to your targets. |
It looks fine, but could you add an adapted version of this test please: https://github.com/Simn/genjvm/blob/7075f8bd4e25d5de50cb879bc589103835e05440/tests/genjvm/src/test/TestExceptions.hx#L25-L32 |
@Simn added |
Hmm, |
That's because throwing a type makes dce to keep |
I for one don't care much for JS hello-throw optimizations. It's fair that throwing an exception comes with a bit of run-time support, so as long as we don't have random |
|
|
Please resolve the conflicts. ... and sorry for causing conflicts! |
Done. |
I was going to merge it this week but we can also wait a bit longer if you prefer. |
Closes #6966
Closes #4159
This PR implements a common cross-target exception handling.
The behavior is configured with the following platform config on ocaml side:
Suggested API on Haxe side: https://github.com/RealyUniqueName/haxe/blob/feature/haxe-error/std/haxe/Exception.hx
Implemented approach brings following benefits:
catch(e:java.lang.Throwable) {} catch(e:Dynamic) {}
)catch
generation (no need forif(Std.is(e, CatchType)
-fest) on targets wherehaxe.Exception
extends a native exception type;Example
Here is an example:
Currently that sample is compiled into following pseudo-code for PHP (and for almost any target):
If a target platform supports typed catch, then with this PR compiled code would be:
If a target platform does not support typed catch (e.g. javascript), the generated code is:
Wildcard catch
haxe.Exception
itself is treated as a wildcard catch:compiled into
Backward compatibility
The new approach still supports throwing and catching values of arbitrary types (like strings and enums), so existing Haxe code would not require any updates.
Non-
haxe.Exception
types get wrapped intohaxe.ValueException
(which extendshaxe.Exception
) and automatically unwrapped on catch:compiled into
However, with this PR merged we should encourage users to throw and catch only
haxe.Exception
-based values.Checklist
Implementation for each target mostly boils down to removing exception handling from the generator and to implementing
haxe.Exception
API