Fixes #1141 and removed StubShutdownHandler
Properly handle all errors.
Move to debug namespace.