-
Notifications
You must be signed in to change notification settings - Fork 203
PHP->JS exception propagation #156
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
Conversation
The test relied on weird behaviour that PHP exceptions shouldn't stop JavaScript code execution. Since JavaScript execution is now stopped, the JavaScript catch handler is not executed anymore.
|
This is looking really good. I did run into some confusion when intentionally calling a method with a missing argument. This raised a TypeError in Javascript which was not a built-in Exception object (PHP5.6) so my expectation of being able to call methods on a PHP Exception object (eg: getMessage()) did not work. Interestingly, doing this natively in PHP simply raises a warning and continues code execution. I would also recommend documenting that err.name will give the type of PHP Exception thrown as I didn't realise that for a while. Code snippet of raising a TypeError: Executing the code produces a V8JsScriptException "TypeError: err.getMessage is not a function" |
|
The But I agree that the destinction between errors and exceptions can become confusing. |
|
V8Js being more strict with TypeError behaviour seems fine, might be good to document though. On the whole, I think the handling as implemented in this request is a significant improvement and will be extremely useful as it currently stands. I notice PHP 7 has TypeError as an Exception object which will resolve my specific example. |
|
@tahpot well yes, but the TypeError object isn't equal to JavaScript TypeError object then ... or won't be until we add some glue, probably. The PHP objects tend to have dedicated getter methods named like getXXX where JS tends to have just the properties, maybe read-only And you're right, there's much documentation to write. So I'll merge after
|
|
FYI -- this pull request also fixes #122 which I recently encountered when using master. |
This pull requests adds (optional) support to propagate PHP exceptions to JavaScript. This can be enabled by passing the
FLAG_PROPAGATE_PHP_EXCEPTIONSflag toexecuteStringmethod.If set, thrown PHP exception objects are converted to JavaScript objects obeying normal conversion behaviour and thrown in JavaScript. This is all public method (and properties) can be used on the caught exception object from JavaScript side.
If JS doesn't catch the exception a V8JsException is thrown that points to the original PHP exception via (private) previous property, that can be got with
getPrevious()method.@tahpot, @rosmo looking forward to your review
this pull request fixes #144