GeneralPurpose-ThrowByValueCatchByReference¶
Throw exceptions by value and catch them by reference
Required inputs: IR
new when throwing exceptions, as it is unclear
who would have the responsibility for freeing the exception object.
Instead, throw exceptions by value.
Catching exceptions by value will lead to object slicing when the thrown exception inherits from the exception type specific in the catch clause. Catch exceptions by reference to allow for polymorphism.
Example
try
{
throw MyException(args);
}
catch (const MyException& ex)
{
...
}
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
catch_without_reference |
Exceptions shall be caught by reference. |
None |
False |
throwing_pointer |
Exceptions shall be thrown by value. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
only_class_types¶
only_class_types : bool = True