You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
I am having some trouble understanding how to use zone.js for global exception handling.
I tried this:
<html>
<head>
<script src="https://unpkg.com/zone.js?main=browser"></script>
<script>
Zone.current.fork({
onHandleError: function(parentZoneDelegate, currentZone, targetZone, error) {
console.log("Error handled by zone: " + error);
}
}).run(function () {
setTimeout(function () {
console.log("In zone setTimeout")
throw new Error("Throw in zone setTimeout");
}, 0);
console.log("Directly in zone");
throw new Error("Throw directly in zone");
});
</script>
</head>
<body>
</body>
</html>
Actual console output:
Directly in zone (test1.html:14)
Uncaught Error: Throw directly in zone (test1.html:15)
In zone setTimeout (test1.html:11 )
Error handled by zone: Error: Throw in zone setTimeout (test1.html:7)
Expected console output:
Directly in zone (test1.html:14)
Error handled by zone: Error: hrow directly in zone (test1.html:7)
In zone setTimeout (test1.html:11 )
Error handled by zone: Error: Throw in zone setTimeout (test1.html:7)
I expect that exceptions thrown directly in the zone, and exceptions thrown by a task scheduled by setTime in the zone, would both invoke the onHandleError handler. Is that a correct expectation? In that case the actual console output avove would indicate a bug. If it is not the expected behaviour, could someone please explain why?