FIX Uncaught Exception appearing in the written log

Capture global exceptions to avoid strange uncaught exception messages in the log files.