-
Notifications
You must be signed in to change notification settings - Fork 395
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
Uncaught exception doesn't raise #170
Comments
I think this works properly. Your function getInfo when executed raises an exception, and never returns its promise. Now it is being executed inside the outer "then", and there's nothing to catch it. If you had used something like a .otherwise() and put the "else" clause of your outer "then" there, following that outer then, then it would have caught it. Basically: Code inside a "then" is sort of in a "promise" state. It can never raise an exception. It is sort of as if you ran it in a try catch block, where you resolve if the try goes through and reject if you fall in the catch part. If you do want to handle that exception, you'll have to do something like: }, function() {
console.log("check FAILED");
})
.otherwise(handleErrorFunction);
} |
@industral yes, @skiadas is on the mark here. I'll try to add a bit of background. Promises provide a powerful asynchronous analog to synchronous exceptions. The promise machinery must catch exceptions and transform them into promise rejections (see 3.2.6.2 in the Promises/A+ spec. Because promises have a temporal component which synchronous exceptions don't, a rejected promise that is "unhandled" in one instant may become handled in some future instant when some code adds a rejection handler to it. Thus, at any instant you might deem a rejection "unhandled", in the very next instant, it might be handled. Rejections still travel back through a promise chain similarly to how exceptions propagate, so adding a rejection handler at a higher level, via One problem is that Javascript VMs aren't yet promise-aware, so rejections that remain unhandled forever will be silent. when.js (>= 2.2.0) includes a promise monitoring system that can detect and report unhandled rejections--it will also detect if/when they later become handled. It will even attempt to stitch together call stacks across event loop turns to recreate a "long stack trace" of the rejection's lifetime (where the promise was created, where it was rejected, etc.) The default monitor reports information to the console, but you could potentially create your own (based on this and this) that rethrows exceptions in a future event-loop tick (and thus are uncatchable), and then install an That's pretty roundabout, though, and I think you'll find that once you get used to handling errors with promises, it's quite intuitive and powerful. Hope that helps! EDIT: Add missing links to monitor console and rethrowToHost code |
@briancavalier Thanks a lot! |
Cool, glad that helped. I forgot to add some links above, so I just edited my comment and added them. |
I found, that if in code I have uncaught exception, and that particular part of code is promise object, exceptions couldn't be catches by "uncaughtException" event.
Here we have
asd.asd
that doesn't exist, but exception haven't catch.In console we have:
check OK
The text was updated successfully, but these errors were encountered: