Skip to content
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

Catch Exceptions by Reference to Avoid Slicing #1990

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ahcox
Copy link

@ahcox ahcox commented Jan 25, 2025

Preserve messages from derived exceptions for more informative logging.

Catching them by value means making a copy of the thrown exception, and if it was actually derived from the type named at the catch point, that will be a slicing copy, throwing away the fields of the derived type which might contain information it uses to provide a helpful what() message. Indeed, the virtual what() function will resolve to the base class version, returning an empty string in the cases of the test apps.

Ref: C++ Core Guidelines, E.15: Throw by value, catch exceptions from a hierarchy by reference.

Preserve messages from derived exceptions for more informative
logging.
@ci-tester-lunarg
Copy link

Author ahcox not on autobuild list. Waiting for curator authorization before starting CI build.

@CLAassistant
Copy link

CLAassistant commented Jan 25, 2025

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants