diff --git a/src/libOpenImageIO/imagebuf.cpp b/src/libOpenImageIO/imagebuf.cpp index fdf14fe447..fdee427361 100644 --- a/src/libOpenImageIO/imagebuf.cpp +++ b/src/libOpenImageIO/imagebuf.cpp @@ -575,10 +575,15 @@ ImageBufImpl::~ImageBufImpl() // how to properly check for errors. if (!m_err.empty() /* Note: safe becausethis is the dtr */ && OIIO::pvt::imagebuf_print_uncaught_errors) { - OIIO::print( - "An ImageBuf was destroyed with a pending error message that was never\n" - "retrieved via ImageBuf::geterror(). This was the error message:\n{}\n", - m_err); + try { + OIIO::print( + "An ImageBuf was destroyed with a pending error message that was never\n" + "retrieved via ImageBuf::geterror(). This was the error message:\n{}\n", + m_err); + } catch (...) { + // Swallow any exceptions (e.g., from fmt's fwrite_fully) + // to avoid std::terminate from throwing in a destructor. + } } } diff --git a/src/libutil/strutil.cpp b/src/libutil/strutil.cpp index dc053df65e..8cef3b9a49 100644 --- a/src/libutil/strutil.cpp +++ b/src/libutil/strutil.cpp @@ -201,10 +201,15 @@ struct ErrorHolder { ~ErrorHolder() { if (!error_msg.empty() && OIIO::pvt::oiio_print_uncaught_errors) { - OIIO::print( - "OpenImageIO exited with a pending error message that was never\n" - "retrieved via OIIO::geterror(). This was the error message:\n{}\n", - error_msg); + try { + OIIO::print( + "OpenImageIO exited with a pending error message that was never\n" + "retrieved via OIIO::geterror(). This was the error message:\n{}\n", + error_msg); + } catch (...) { + // Swallow any exceptions (e.g., from fmt's fwrite_fully) + // to avoid std::terminate from throwing in a destructor. + } } } };