Catch instanceof guards

It would be really nice to be able to write

try {
    // some code
} catch (error instanceof MyCustomError) {
    // handle the error
} catch (error instanceof AnotherCustomError) {
    // handle the other error
}

instead of the more verbose

try {
    // some code
} catch (error) {
    if (error instanceof MyCustomError) {
        // handle the error
    } else if (error instanceof AnotherCustomError) {
        // handle the other error
    } else {
        throw error;
    }
}

possible duplicate of Specific Exception Handling :slightly_smiling_face:

1 Like

It's indeed a duplicate.

1 Like