Created
January 5, 2021 08:45
-
-
Save zlatkov/d3e4a49310ea60d861042a2f56ffc91f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
If (typeof x !== ‘number’) { | |
throw new TypeError(‘x is not a number’); | |
} else if (x <= 0) { | |
throw new RangeError(‘x should be greater than 0’); | |
} else { | |
// Do something useful | |
} | |
} catch (err) { | |
if (err instanceof TypeError) { | |
// Handle TypeError exceptions | |
} else if (err instanceof RangeError) { | |
// Handle RangeError exceptions | |
} else { | |
// Handle all other types of exceptions | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment