added exception handling to warn when application is shutting down