Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var add = function(a, b) {
if(typeof a !== 'number' || typeof b !== 'number') {
throw {
name : 'TypeError',
message : 'add needs numbers'
}
}
return a + b;
}
var try_it = function() {
try {
add("seven");
} catch (e) {
console.log(e.name + ' : ' + e.message);
// TypeError : add needs numbers
}
}
try_it();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment