Skip to content

Instantly share code, notes, and snippets.

@frostbytten
Created May 20, 2011 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frostbytten/983546 to your computer and use it in GitHub Desktop.
Save frostbytten/983546 to your computer and use it in GitHub Desktop.
Closure JS try-catch
app.error(function( err, req, res, next ){
console.log(err);
if( ! ( err instanceof SoftError ) ) {
console.log(err.stack);
res.render('errors.ejs', {error: err.message || err.name });
}
});
app.all('/errr', function( req, res ){
try {
db.open( function( err, db ){
if(party.is.happening === true ) console.log('Awesome');
});
} catch( e ) {
console.log('ERROR TYPE:'+e.name);
if( e instanceof SoftError ) {
console.log(e.stack);
res.end();
} else {
throw e;
}
} finally {
db.close();
console.log('Called /errr finally');
}
});
// The great equalizer
process.on('uncaughtException', function (err) {
console.log('Uncaught exception\n------------------\n',err.stack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment