Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active August 29, 2015 14:10
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 kkoziarski/01516a1dc58c1c560d83 to your computer and use it in GitHub Desktop.
Save kkoziarski/01516a1dc58c1c560d83 to your computer and use it in GitHub Desktop.
Exceptions - The Good Parts
var add = function (a, b) {
if (typeof a !== 'number' || typeof b !== 'number') {
throw {
name: 'TypeError',
message: 'add needs numbers'
};
}
return a + b;
}
// Make a try_it function that calls the new add
// function incorrectly.
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