add exception handling code for abnormal app termination