Implementation for Issue #5: OnException

Please review the original issue #5 and this implementation code. I'll be glad to answer any questions you have about the code and fix any possible issues.

Getting these changes to your mainline would mean a lot.