How to determine what type of error an exception is in JS

problem description

A code may throw error An or error B
. The two errors are handled differently. After capture, you need to determine which error
after capturing an exception error, does error only have message, that can only match the string determination problem in message? But message should not be just for people to see, string matching is not accurate, is it?

Jun.09,2021

clipboard.png


errorerrormessage

Errormessage, filname, lineNumbermessage

clipboard.png

in addition, you can also define your own class inheritance base class, implement the fields you want, or even error type fields. However, it is not recommended.
recommends distinguishing between different types of errors.

details: https://developer.mozilla.org.

Menu