I already read this post: Why does instanceof return false for some literals?
But didn't find any information about Error
object work with instanceof
operator. Here is my example:
class ErrorType1 extends Error {
constructor(message) {
super(message);
}
}
class ErrorType2 extends Error {
constructor(message) {
super(message);
}
}
function someOperation(data) {
if (data === 1) {
throw new ErrorType1('error 1');
} else if (data === 2) {
throw new ErrorType2('error 2');
} else if (data === 0) {
throw new Error('unknown error');
}
}
function main(data) {
try {
someOperation(data)
} catch(e) {
console.log(e instanceof ErrorType2)
if (e instanceof ErrorType1) {
console.log(11)
return e
} else if (e instanceof ErrorType2) {
console.log(22)
return e
}
console.log(333)
throw e;
}
}
main(2)
I expected the e instanceof ErrorType2
expression should return a true
value. But the stdout give me an false
value and the console.log(333)
statement executed. Here is the result:
Do I missing anything?
UPDATE
I used to guess it's my network issue, maybe some static resources don't load. But after I turn on the VPN, the result is same.