A collection of various JavaScript error handling techniques.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
LICENSE
README.md
domain-bound-exceptions.js
error-callbacks-node.js
error-callbacks.js
promises.js
synchronous-exception.js
synchronous-return-value.js

README.md

JavaScript error handling examples

This is a collection of various JavaScript error handling techniques.

  • synchronous
    • synchronous-return-value: indicate error through return value
    • synchronous-exception: throw an exception if an error occurs
  • asynchronous
    • error-callbacks: call additional error callback
    • error-callbacks-node: call regular callback with error argument
    • promises: return a promise object
    • domain-bound-execptions: use Node.js domains

Usage

Run a file without arguments to watch it fail; pass an argument for success.

$ ./promises.js
Letter not sent: Cannot reach address empty
$ ./promises.js London
Letter sent with code XYZ-London

Read more

This code accompanies the blog post Asynchronous error handling in JavaScript, which discusses the use case.