Browse Source

Create a central exception handler we can also use to generate sentry events

newinvert
Marek Roszko 3 years ago
parent
commit
c5d5450f55
  1. 33
      common/pgm_base.cpp
  2. 41
      common/single_top.cpp
  3. 3
      include/pgm_base.h

33
common/pgm_base.cpp

@ -55,6 +55,7 @@
#include <kicad_curl/kicad_curl.h> #include <kicad_curl/kicad_curl.h>
#include <kiplatform/policy.h> #include <kiplatform/policy.h>
#include <lockfile.h> #include <lockfile.h>
#include <macros.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#include <paths.h> #include <paths.h>
#include <pgm_base.h> #include <pgm_base.h>
@ -880,4 +881,36 @@ bool PGM_BASE::IsGUI()
bool run_gui = wxTheApp->GetClassName() != KICAD_CLI_APP_NAME; bool run_gui = wxTheApp->GetClassName() != KICAD_CLI_APP_NAME;
return run_gui; return run_gui;
#endif #endif
}
void PGM_BASE::HandleException( std::exception_ptr aPtr )
{
try
{
if( aPtr )
std::rethrow_exception( aPtr );
}
catch( const IO_ERROR& ioe )
{
wxLogError( ioe.What() );
}
catch( const std::exception& e )
{
#ifdef KICAD_USE_SENTRY
sentry_value_t exc = sentry_value_new_exception( "exception", e.what() );
sentry_value_set_stacktrace( exc, NULL, 0 );
sentry_value_t sentryEvent = sentry_value_new_event();
sentry_event_add_exception( sentryEvent, exc );
sentry_capture_event( sentryEvent );
#endif
wxLogError( wxT( "Unhandled exception class: %s what: %s" ),
FROM_UTF8( typeid( e ).name() ), FROM_UTF8( e.what() ) );
}
catch( ... )
{
wxLogError( wxT( "Unhandled exception of unknown type" ) );
}
} }

41
common/single_top.cpp

@ -52,6 +52,9 @@
#include <kiplatform/app.h> #include <kiplatform/app.h>
#include <kiplatform/environment.h> #include <kiplatform/environment.h>
#ifdef KICAD_USE_SENTRY
#include <sentry.h>
#endif
// Only a single KIWAY is supported in this single_top top level component, // Only a single KIWAY is supported in this single_top top level component,
// which is dedicated to loading only a single DSO. // which is dedicated to loading only a single DSO.
@ -159,18 +162,9 @@ struct APP_SINGLE_TOP : public wxApp
{ {
return program.OnPgmInit(); return program.OnPgmInit();
} }
catch( const std::exception& e )
{
wxLogError( wxT( "Unhandled exception class: %s what: %s" ),
FROM_UTF8( typeid( e ).name() ), FROM_UTF8( e.what() ) );
}
catch( const IO_ERROR& ioe )
{
wxLogError( ioe.What() );
}
catch(...)
catch( ... )
{ {
wxLogError( wxT( "Unhandled exception of unknown type" ) );
Pgm().HandleException( std::current_exception() );
} }
program.OnPgmExit(); program.OnPgmExit();
@ -192,18 +186,9 @@ struct APP_SINGLE_TOP : public wxApp
{ {
ret = wxApp::OnRun(); ret = wxApp::OnRun();
} }
catch( const std::exception& e )
{
wxLogError( wxT( "Unhandled exception class: %s what: %s" ),
FROM_UTF8( typeid( e ).name() ), FROM_UTF8( e.what() ) );
}
catch( const IO_ERROR& ioe )
{
wxLogError( ioe.What() );
}
catch(...) catch(...)
{ {
wxLogError( wxT( "Unhandled exception of unknown type" ) );
Pgm().HandleException( std::current_exception() );
} }
return ret; return ret;
@ -254,19 +239,9 @@ struct APP_SINGLE_TOP : public wxApp
{ {
throw; throw;
} }
catch( const std::exception& e )
{
wxLogError( "Unhandled exception class: %s what: %s",
FROM_UTF8( typeid(e).name() ),
FROM_UTF8( e.what() ) );
}
catch( const IO_ERROR& ioe )
{
wxLogError( ioe.What() );
}
catch(...)
catch( ... )
{ {
wxLogError( "Unhandled exception of unknown type" );
Pgm().HandleException( std::current_exception() );
} }
return false; // continue on. Return false to abort program return false; // continue on. Return false to abort program

3
include/pgm_base.h

@ -31,6 +31,7 @@
#ifndef PGM_BASE_H_ #ifndef PGM_BASE_H_
#define PGM_BASE_H_ #define PGM_BASE_H_
#include <exception>
#include <map> #include <map>
#include <vector> #include <vector>
#include <memory> #include <memory>
@ -303,6 +304,8 @@ public:
const wxString& GetSentryId(); const wxString& GetSentryId();
#endif #endif
void HandleException( std::exception_ptr ptr );
/** /**
* Determine if the application is running with a GUI * Determine if the application is running with a GUI
* *

Loading…
Cancel
Save