From 20bd4e9b2302bb696381c76ee3d605b980edf74b Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 11 May 2009 21:52:19 +0000 Subject: [PATCH] fixed no try catch block for exceptions occurring when fetching the time to print a diagnostic message in the last chance exception handler. --- src/libCom/osi/epicsThread.cpp | 61 ++++++++++++++++++---------------- src/libCom/osi/epicsThread.h | 4 ++- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/libCom/osi/epicsThread.cpp b/src/libCom/osi/epicsThread.cpp index f31d445c0..052609c2f 100644 --- a/src/libCom/osi/epicsThread.cpp +++ b/src/libCom/osi/epicsThread.cpp @@ -15,9 +15,10 @@ #include #include -#include -#include -#include +#include +#include +#include +#include #define epicsExportSharedSymbols #include "epicsAlgorithm.h" @@ -30,6 +31,30 @@ epicsThreadRunable::~epicsThreadRunable () {} void epicsThreadRunable::run () {} void epicsThreadRunable::show ( unsigned int ) const {} + +void epicsThread :: printLastChanceExceptionMessage ( + const char * pExceptionTypeName, + const char * pExceptionContext ) +{ + char date[64]; + try { + epicsTime cur = epicsTime :: getCurrent (); + cur.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f"); + } + catch ( ... ) { + strcpy ( date, "" ); + } + char name [128]; + epicsThreadGetName ( this->id, name, sizeof ( name ) ); + errlogPrintf ( + "epicsThread: Unexpected C++ exception \"%s\" with type \"%s\" in thread \"%s\" at %s\n", + pExceptionContext, pExceptionTypeName, name, date ); + errlogFlush (); + // this should behave as the C++ implementation intends when an + // exception isnt handled. If users dont like this behavior, they + // can install an application specific unexpected handler. + std::unexpected (); +} extern "C" void epicsThreadCallEntryPoint ( void * pPvt ) { @@ -49,36 +74,14 @@ extern "C" void epicsThreadCallEntryPoint ( void * pPvt ) } catch ( std::exception & except ) { if ( ! waitRelease ) { - epicsTime cur = epicsTime::getCurrent (); - char date[64]; - cur.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f"); - char name [128]; - epicsThreadGetName ( pThread->id, name, sizeof ( name ) ); - errlogPrintf ( - "epicsThread: Unexpected C++ exception \"%s\" with type \"%s\" in thread \"%s\" at %s\n", - except.what (), typeid ( except ).name (), name, date ); - errlogFlush (); - // this should behave as the C++ implementation intends when an - // exception isnt handled. If users dont like this behavior, they - // can install an application specific unexpected handler. - std::unexpected (); + pThread->printLastChanceExceptionMessage ( + typeid ( except ).name (), except.what () ); } } catch ( ... ) { if ( ! waitRelease ) { - epicsTime cur = epicsTime::getCurrent (); - char date[64]; - cur.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f"); - char name [128]; - epicsThreadGetName ( pThread->id, name, sizeof ( name ) ); - errlogPrintf ( - "epicsThread: Unknown C++ exception in thread \"%s\" at %s\n", - name, date ); - errlogFlush (); - // this should behave as the C++ implementation intends when an - // exception isnt handled. If users dont like this behavior, they - // can install an application specific unexpected handler. - std::unexpected (); + pThread->printLastChanceExceptionMessage ( + "catch ( ... )", "Non-standard C++ exception" ); } } if ( ! waitRelease ) { diff --git a/src/libCom/osi/epicsThread.h b/src/libCom/osi/epicsThread.h index 015bc2f1c..58be09f66 100644 --- a/src/libCom/osi/epicsThread.h +++ b/src/libCom/osi/epicsThread.h @@ -174,7 +174,9 @@ private: epicsThread ( const epicsThread & ); epicsThread & operator = ( const epicsThread & ); friend void epicsThreadCallEntryPoint ( void * ); - + void printLastChanceExceptionMessage ( + const char * pExceptionTypeName, + const char * pExceptionContext ); /* exceptions */ class exitException {}; };