Fix shutdown reason logging on exception in main block