You can try something like 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");
});
</script>
</head>
<body>
</body>
</html>
Which would catch the exception in the user-defined handler indicated onHandleError, and throw an output like this:
Directly in zone (test1.html:14)
In zone setTimeout (test1.html:11 )
Error handled by zone: Error: Throw in zone setTimeout (test1.html:7)
However, this does not seem to work if exceptions are thrown directly in the zone. I registered and issue about it.
source
share