Factor out the exception handling in the startup code to a utility function, and fix the some logging and exit code stuff.