Added onError

Adds an "onError" option which takes a function is called when any exceptions are hit.