Skip to content

Instantly share code, notes, and snippets.

@seanmonstar
Created September 6, 2011 02:21
Show Gist options
  • Select an option

  • Save seanmonstar/1196406 to your computer and use it in GitHub Desktop.

Select an option

Save seanmonstar/1196406 to your computer and use it in GitHub Desktop.
Coffee exceptions
req = (request, errorOnTimeout) ->
try
request.send
catch InvalidHeaderError, e
console.error 'wrong headers'
catch TimeoutError, e
if errorOnTimeout
console.error 'timed out!'
else
console.log 'timed out, trying once more'
req(request, true)
catch Error, e
console.log 'some other error'
function request(request, errorOnTimeout) {
try {
request.send();
} catch (error) {
if (error instanceof InvalidHeaderError) {
var e = error;
console.error('wrong headers');
} else if (error instanceof TimeoutError) {
var e = error;
if (errorOnTimeout) {
console.error('timed out!');
} else {
console.log('timed out, trying again');
req(request, true);
}
} else if (error instanceof Error) {
var e = error;
console.log('some other error');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment