Add global error handling code
merged in upstream changes
code review changes
Merge pull request #416 from dburdick/swc-284

Add global error handling code