handling exception while closing app instance