Skip to content

ERRCODE::error: throw std::runtime_error instead of abort() #4420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/ccutil/errcode.cpp
Original file line number Diff line number Diff line change
@@ -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<int *>(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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it? It does not print a stack trace in my test on macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, I get:

ELIST_ITERATOR::forward:Error:List would have returned a nullptr data pointer
terminate called after throwing an instance of 'std::runtime_error'
  what():  ELIST_ITERATOR::forward:Error:List would have returned a nullptr data pointer
Abgebrochen (Speicherabzug geschrieben)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a stack trace. And please rebase your code with all recent updates from the main branch. Then you will no longer get a core dump.

Comment on lines +73 to +76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
// Abort unless std::runtime_error is caught by the application.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is more precise. But I'd like to also comment what used to be the behaviour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There used to be comments about the history of some code parts in the past, but most of them are removed in the recent code. I don't think that new comments of this kind are helpful.

throw std::runtime_error(msg.str());
default:
BADERRACTION.error("error", ABORT);
}
Loading
Oops, something went wrong.