Skip to content

Instantly share code, notes, and snippets.

@zlatkov
Created January 5, 2021 08:45
Show Gist options
  • Save zlatkov/d3e4a49310ea60d861042a2f56ffc91f to your computer and use it in GitHub Desktop.
Save zlatkov/d3e4a49310ea60d861042a2f56ffc91f to your computer and use it in GitHub Desktop.
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