From 61517cff2dbb9923cc78297156f07926e2ab8b11 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Wed, 7 May 2025 16:16:00 +0200 Subject: [PATCH] ERRCODE::error: throw std::runtime_error instead of abort() --- src/ccutil/errcode.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/ccutil/errcode.cpp b/src/ccutil/errcode.cpp index e6b05c213c..4b288e9aae 100644 --- a/src/ccutil/errcode.cpp +++ b/src/ccutil/errcode.cpp @@ -70,17 +70,11 @@ void ERRCODE::error( // handle error return; // report only case TESSEXIT: case ABORT: -#if !defined(NDEBUG) - // Create a deliberate abnormal exit as the stack trace is more useful - // that way. This is done only in debug builds, because the - // error message "segmentation fault" confuses most normal users. -# if defined(__GNUC__) - __builtin_trap(); -# else - *reinterpret_cast(0) = 0; -# endif -#endif - abort(); + // This used to trigger a segfault or abort(); + // However, at least for library use, only exceptions should be acceptable. + // Even in the standalone application case, exceptions are better, + // because the default handler will print the message along with the stack trace. + throw std::runtime_error(msg.str()); default: BADERRACTION.error("error", ABORT); }