Created
May 30, 2015 20:30
-
-
Save rootid/fcdc32a12dc852319b4f to your computer and use it in GitHub Desktop.
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
//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