Use a thrown error instead of calling msg_dialog and exit. And use an exception handler to format uncaught fatal errors. issue #6071