Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Created February 10, 2012 16:48
Show Gist options
  • Save briancavalier/1790802 to your computer and use it in GitHub Desktop.
Save briancavalier/1790802 to your computer and use it in GitHub Desktop.
try/catch example
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