Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active Aug 29, 2015
Embed
What would you like to do?
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