Last active
August 29, 2015 14:10
-
-
Save kkoziarski/01516a1dc58c1c560d83 to your computer and use it in GitHub Desktop.
Exceptions - The Good Parts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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