CA Client: Protect against epicsTime::strftime() throwing

libCa shouldn't cause an application to abort with an uncaught
exception on a machine that has timezone problems just because
we can't convert the current time into a string.
This commit is contained in:
Andrew Johnson
2022-04-24 12:50:40 -05:00
parent 492672c718
commit e329fa3296

View File

@@ -392,9 +392,19 @@ void ca_client_context :: vSignal (
}
epicsTime current = epicsTime::getCurrent ();
char date[64];
current.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f");
this->printFormated ( " Current Time: %s\n", date );
try {
char date[64];
current.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f");
this->printFormated ( " Current Time: %s\n", date );
}
catch ( std::exception & except ) {
errlogPrintf (
"CA client library thread \"%s\" caught C++ exception \"%s\"\n",
epicsThreadGetNameSelf (), except.what () );
epicsTimeStamp now = current;
this->printFormated ( " Current Time: %u.%u\n",
now.secPastEpoch, now.nsec );
}
/*
* Terminate execution if unsuccessful