Skip to content

Instantly share code, notes, and snippets.

@xk
Created September 12, 2011 23:27
Show Gist options
  • Select an option

  • Save xk/1212757 to your computer and use it in GitHub Desktop.

Select an option

Save xk/1212757 to your computer and use it in GitHub Desktop.
app status
var appStatus;
process.on('uncaughtException', function globalErrHandler (error) {
console.log('An error happened when the appStatus was '+ appStatus);
switch (appStatus) {
case 1: //recover from status 1
case 2: //idem from status 2
case 3: //etc.
case 4:
}
process.nextTick(loop); //keep going
});
function mayThrow () { if (Math.random() > 0.999999) throw Error() }
function loop () {
appStatus= 1, mayThrow();
appStatus= 2, mayThrow();
appStatus= 3, mayThrow();
appStatus= 4, mayThrow();
process.nextTick(loop);
}
loop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment