-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs($exceptionHandler): add a note about cases when exceptions are not delegated... #9318
Conversation
3067900
to
c87f5f3
Compare
* {@link ng.$http $http} for XHR, {@link ng.$timeout $timeout}/{@link ng.$interval $interval} for | ||
* setTimeout/setInterval). For the rest, you can explicitly ensure that the code is excecuted | ||
* inside of the Angular context, by wrapping it in | ||
* {@link ng.$rootScope.Scope#$apply scope.$apply()}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or you could just manually do
try {
doAThingThatMightThrow();
} catch (e) {
$exceptionHandler(e);
}
This is a pretty detailed and long-winded explanation, I think we can condense this down a bit so that it's easier for people to read. SGTY?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try/catch
does only take care of exception handling (no $digest-ing). It would get even more verbose to mention both options (and the consequences of each) and since I mention functions executing outside of the Angular context, I rather wouldn't propose a solution that does not address this (out-of-context issue), but only exception-handling.
That said, if you think it's better to remove all that "Angular context" stuff and just keep it down to exception handling it's fine by me.
Or maybe all the examples should go away.
No idea what SGTY
is though... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$digest is completely unrelated to $exceptionHandler, so it doesn't make sense to bring it up (except maybe to mention that things which happen during digest will pass caught exceptions to $exceptionHandler).
SGTY is "sound good to you"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caitp, how about those versions:
Note, that code executed outside of the Angular context does not delegate exceptions to the $exceptionHandler
(e.g. functions invoked by third party libraries and callbacks associated with XHR, setTimeout/setInterval and browser DOM events (including callbacks registered using jqLite's/jQuery's on
/bind
methods)).
For some of those cases, Angular provides native wrappers that take a care of exception handling (e.g. $http
, $timeout
/$interval
). For the rest, you can explicitly delegate exceptions to the $exceptionHandler
, e.g.:
try {
...
} catch (e) {
$exceptionHandler(e);
}
Note, that code executed inside of event-listeners (even those registered using jqLite's/jQuery's on
/bind
methods) does not delegate exceptions to the $exceptionHandler
(unless executed during a digest).
If you wish, you can manually delegate exceptions (e.g. try {...} catch(e) {$exceptionHandler(e);}
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abdaab7
to
30996f8
Compare
…ot delegated to the $exceptionHandler Add a note in $exceptionHandler's documentation about cases when exceptions are not delegated to the $exceptionHandler, because they are executed outside of the Angular context. Most notable such cases being the DOM event listeners registered using jqLite's/jQuery's on/bind methods. Closes angular#7909
c87f5f3
to
f2a5402
Compare
@@ -27,6 +27,14 @@ | |||
* This example will override the normal action of `$exceptionHandler`, to make angular | |||
* exceptions fail hard when they happen, instead of just logging to the console. | |||
* | |||
* <hr /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add in the detail from @gkalpak that anything executed outside the AJS context will run into this issue...here's my quick edit:
Note, code executed outside of the Angular context, most commonly DOM event listeners (even those registered using jqLite's on
/bind
methods), will not delegate exceptions to the {@link ng.$exceptionHandler $exceptionHandler} (unless executed during a digest).
...to the $exceptionHandler
Add a note in $exceptionHandler's documentation about cases when exceptions are not delegated to the
$exceptionHandler, because they are executed outside of the Angular context. Most notable such
cases being the DOM event listeners registered using jqLite's/jQuery's on/bind methods.
Closes #7909