Catch exception when removing shutdown hook