Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Bug in onHandleError? #429

@jonaskello

Description

@jonaskello

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions