AutosarC++17_03-A15.3.5

A class type exception shall be caught by reference or const reference

Required inputs: IR

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, and to avoid unnecessary copies.

Example
try
{
    throw MyException(args);
}
catch (const MyException& ex)
{
    ...
}

Possible Messages

Key

Text

Severity

Disabled

catch_without_reference

A class type exception shall always be caught by reference.

None

False

Options

only_class_types

only_class_types : bool = True

Whether all types should be caught by reference or only class types.