Skip to content

New rule proposal: exception types should be nothrow copyable #1921

@szaszm

Description

@szaszm

There is a similar rule in the SEI CERT C++ Coding Standard: ERR60-CPP. Exception objects must be nothrow copy constructible (down at the time of submitting this issue).

Rationale: exception objects are copy-initialized, and if an implementation chooses to not elide this copy, or there is an additional copy at the catch site (i.e. not following E.15: Throw by value, catch exceptions from a hierarchy by reference), and the copy constructor throws, then std::terminate is called.

It's sufficient if the exception type is nothrow copy constructible, but I can't see why someone would want to make a throwing copy assignment operator at the same time, aside from doing some magic in the copy constructor and not bothering to define a copy assignment operator, but that already violates the rule of three / five.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions