Created
February 10, 2012 16:48
-
-
Save briancavalier/1790802 to your computer and use it in GitHub Desktop.
try/catch example
This file contains 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
function thisMightFail() { | |
//... | |
if(badThingsHappened) { | |
throw new Error(...); | |
} | |
return theGoodResult; | |
} | |
function recoverFromFailure(e) { | |
//... | |
return recoveryValue; | |
} | |
function getTheResult() { | |
var result; | |
try { | |
result = thisMightFail(); | |
} catch(e) { | |
result = recoverFromFailure(e); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment