@@ -295,22 +295,23 @@ Noggit::Noggit(int argc, char *argv[])
295
295
296
296
namespace
297
297
{
298
- void noggit_terminate_handler ()
298
+ std::string current_exception_string ()
299
299
{
300
- std::string const reason
301
- {util::exception_to_string (std::current_exception ())};
302
-
303
- if (qApp)
304
- {
305
- QMessageBox::critical ( nullptr
306
- , " std::terminate"
307
- , QString::fromStdString (reason)
308
- , QMessageBox::Close
309
- , QMessageBox::Close
310
- );
311
- }
300
+ return util::exception_to_string (std::current_exception ());
301
+ }
312
302
313
- LogError << " std::terminate: " << reason << std::endl;
303
+ void current_exception_messagebox (QString title)
304
+ {
305
+ QMessageBox::critical ( nullptr
306
+ , title
307
+ , QString::fromStdString (current_exception_string ())
308
+ , QMessageBox::Close
309
+ , QMessageBox::Close
310
+ );
311
+ }
312
+ void current_exception_log (std::string title)
313
+ {
314
+ LogError << title << " : " << current_exception_string () << std::endl;
314
315
}
315
316
316
317
struct application_with_exception_printer_on_notify : QApplication
@@ -325,22 +326,55 @@ namespace
325
326
}
326
327
catch (...)
327
328
{
328
- std::terminate ();
329
+ current_exception_messagebox (" event loop exception" );
330
+ current_exception_log (" event loop exception" );
331
+
332
+ exit (1 );
333
+
334
+ return false ;
329
335
}
330
336
}
331
337
};
332
338
}
333
339
334
340
int main (int argc, char *argv[])
341
+ try
335
342
{
336
343
noggit::RegisterErrorHandlers ();
337
- std::set_terminate (noggit_terminate_handler);
344
+ std::set_terminate
345
+ ( []
346
+ {
347
+ if (qApp)
348
+ {
349
+ current_exception_messagebox (" std::terminate" );
350
+ }
338
351
339
- QApplication qapp (argc, argv);
352
+ current_exception_log (" std::terminate" );
353
+ }
354
+ );
355
+
356
+ application_with_exception_printer_on_notify qapp (argc, argv);
340
357
qapp.setApplicationName (" Noggit" );
341
358
qapp.setOrganizationName (" Noggit" );
342
359
343
- Noggit app (argc, argv);
360
+ // ! \note Extra level here because we won't have a qapp below,
361
+ // ! but we still want to not std::terminate if throwing above either.
362
+ try
363
+ {
364
+ Noggit app (argc, argv);
365
+
366
+ return qapp.exec ();
367
+ }
368
+ catch (...)
369
+ {
370
+ current_exception_messagebox (" top level exception" );
371
+
372
+ throw ;
373
+ }
374
+ }
375
+ catch (...)
376
+ {
377
+ current_exception_log (" top level exception" );
344
378
345
- return qapp. exec () ;
379
+ return 1 ;
346
380
}
0 commit comments