MP1-4155: added exception handler to ensure that logs will be flushed