added code to handle uncaughtException