Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created July 28, 2012 17:41
Show Gist options
  • Save fivetanley/3194135 to your computer and use it in GitHub Desktop.
Save fivetanley/3194135 to your computer and use it in GitHub Desktop.
Error Callback with try/catch
// Disclaimer: I am probably pretty wrong about this.
thing.handle( function( err, data ) {
try {
if ( err ) throw err
// js doesn't support specific errors like this, you can only catch a generic error...
} catch( NoNetworkConnection e ) {
window.alert( 'check your internet connection' )
} catch( InvalidPassword err ) {
window.alert( 'check your password' )
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment