[#1731] Improve error handling in onApplicationStop() method