Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 8, 2015 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/07be5905294a7ca663a4 to your computer and use it in GitHub Desktop.
Save chuck0523/07be5905294a7ca663a4 to your computer and use it in GitHub Desktop.
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