Skip to content

Instantly share code, notes, and snippets.

@rootid
Created May 30, 2015 20:30
Show Gist options
  • Save rootid/fcdc32a12dc852319b4f to your computer and use it in GitHub Desktop.
Save rootid/fcdc32a12dc852319b4f to your computer and use it in GitHub Desktop.
//add the given argument and throw exception object {name,message}
var add = function (a, b) {
if (typeof a !== 'number' || typeof b !== 'number') {
throw {
name: 'TypeError',
message: 'add needs numbers'
};
}
return a + b;
}
//catch the exception
var try_it = function () {
try {
add("seven");
} catch (e) {
document.writeln(e.name + ': ' + e.message);
}
}
try_it( );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment