From 63d8988bf11bed0122a53970c8c99c9da0f5cb6d Mon Sep 17 00:00:00 2001 From: Mark Roszko Date: Tue, 6 Jan 2026 20:52:31 -0500 Subject: [PATCH] Implement OnUnhandledException and point to sentry Some "crashes" are just unhandled exceptions that may not get logged to sentry otherwise. (though they should through WER but it doesnt seem to always work) --- common/pgm_base.cpp | 14 +++++++++++++- common/single_top.cpp | 6 ++++++ include/pgm_base.h | 2 +- kicad/kicad.cpp | 12 ++++++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index 1304b54507..1925989070 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -805,7 +805,7 @@ bool PGM_BASE::IsGUI() } -void PGM_BASE::HandleException( std::exception_ptr aPtr ) +void PGM_BASE::HandleException( std::exception_ptr aPtr, bool aUnhandled ) { try { @@ -815,6 +815,12 @@ void PGM_BASE::HandleException( std::exception_ptr aPtr ) catch( const IO_ERROR& ioe ) { wxLogError( ioe.What() ); + + if( aUnhandled ) + { + // Log this IO_ERROR escaped our usual uses (bad) + APP_MONITOR::SENTRY::Instance()->LogException( ioe.What() ); + } } catch( const std::exception& e ) { @@ -825,7 +831,13 @@ void PGM_BASE::HandleException( std::exception_ptr aPtr ) } catch( ... ) { + // We really shouldn't have these but just in case... wxLogError( wxT( "Unhandled exception of unknown type" ) ); + + if( aUnhandled ) + { + APP_MONITOR::SENTRY::Instance()->LogException( "Unhandled exception of unknown type" ); + } } } diff --git a/common/single_top.cpp b/common/single_top.cpp index 4dab54d4bb..80947f844f 100644 --- a/common/single_top.cpp +++ b/common/single_top.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -278,6 +279,11 @@ struct APP_SINGLE_TOP : public wxApp return Event_Skip; } + void OnUnhandledException() override + { + Pgm().HandleException( std::current_exception(), true ); + } + #if defined( DEBUG ) /** * Override main loop exception handling on debug builds. diff --git a/include/pgm_base.h b/include/pgm_base.h index 6092dfa653..6d74bd603a 100644 --- a/include/pgm_base.h +++ b/include/pgm_base.h @@ -321,7 +321,7 @@ public: * * @param aPtr Pass the std::current_exception() from within the catch block. */ - void HandleException( std::exception_ptr aPtr ); + void HandleException( std::exception_ptr aPtr, bool aUnhandled = false ); /** * A common assert handler to be used between single_top and kicad. diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index ebbb57dbb4..9c76ebbb12 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -511,7 +511,7 @@ struct APP_KICAD : public wxApp return true; } - int OnExit() override + int OnExit() override { program.OnPgmExit(); @@ -521,7 +521,8 @@ struct APP_KICAD : public wxApp return wxApp::OnExit(); } - int OnRun() override + + int OnRun() override { try { @@ -535,6 +536,13 @@ struct APP_KICAD : public wxApp return -1; } + + void OnUnhandledException() override + { + Pgm().HandleException( std::current_exception(), true ); + } + + int FilterEvent( wxEvent& aEvent ) override { if( aEvent.GetEventType() == wxEVT_SHOW )