@@ -335,40 +335,40 @@ void ScriptError::SetHandledByDebugger(bool handled)
335335 m_HandledByDebugger = handled;
336336}
337337
338- posix_error::~posix_error () throw ()
338+ const char * posix_error::what () const noexcept
339339{
340- free (m_Message);
341- }
342-
343- const char *posix_error::what () const throw ()
344- {
345- if (!m_Message) {
346- std::ostringstream msgbuf;
347-
348- const char * const *func = boost::get_error_info<boost::errinfo_api_function>(*this );
349-
350- if (func)
351- msgbuf << " Function call '" << *func << " '" ;
352- else
353- msgbuf << " Function call" ;
354-
355- const std::string *fname = boost::get_error_info<boost::errinfo_file_name>(*this );
340+ if (m_Message.IsEmpty ()) {
341+ try {
342+ const char * const * func = boost::get_error_info<boost::errinfo_api_function>(*this );
343+ if (func) {
344+ m_Message += " Function call '" + std::string (*func) + " '" ;
345+ } else {
346+ m_Message += " Function call" ;
347+ }
356348
357- if (fname)
358- msgbuf << " for file '" << *fname << " '" ;
349+ const std::string* fname = boost::get_error_info<boost::errinfo_file_name>(*this );
359350
360- msgbuf << " failed" ;
351+ if (fname) {
352+ m_Message += " for file '" + *fname + " '" ;
353+ }
361354
362- const int *errnum = boost::get_error_info<boost::errinfo_errno>(* this ) ;
355+ m_Message += " failed " ;
363356
364- if (errnum)
365- msgbuf << " with error code " << *errnum << " , '" << strerror (*errnum) << " '" ;
357+ const int * errnum = boost::get_error_info<boost::errinfo_errno>(*this );
366358
367- String str = msgbuf.str ();
368- m_Message = strdup (str.CStr ());
359+ if (errnum) {
360+ m_Message += " with error code " + std::to_string (*errnum) + " , '" + strerror (*errnum) + " '" ;
361+ }
362+ } catch (const std::bad_alloc&) {
363+ m_Message.Clear ();
364+ return " Exception in 'posix_error::what()': bad_alloc" ;
365+ } catch (...) {
366+ m_Message.Clear ();
367+ return " Exception in 'posix_error::what()'" ;
368+ }
369369 }
370370
371- return m_Message;
371+ return m_Message. CStr () ;
372372}
373373
374374ValidationError::ValidationError (const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message)
0 commit comments