AutosarC++17_10-A15.4.6¶
Unchecked exceptions should not be specified together with a function declaration
Required inputs: IR
| Level | advisory |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Unchecked exceptions are those which do not have an appropriate application-specific handling by the caller - it is only needed to catch them in main (or in task main functions). Specifying them is a significant overhead, while they do not bring added value and they restrict the evolution of functions. Such exceptions can occur anywhere in a program, and in a typical one they can be very numerous. Having to add such exceptions in every method declaration would reduce a program’s clarity.
Exceptions
Specifying unchecked exceptions in function declarations by C++ Standard Library does not violate this rule. Standard library can not know if an exception is meaningful for the caller.
Example
//% $Id: A15-4-6.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
#include <stdexcept>
class InvalidInitParameters : public std::logic_error {
public:
using std::logic_error::logic_error;
};
/// @throw InvalidInitParameters Error caused by passing invalid initialization
/// parameters
void Send1(std::uint8_t *buffer, std::uint8_t bufferLengtd) noexcept(
false) // Non-compliant - unchecked exception documented
{
// ...
throw InvalidInitParameters("Invalid parameters");
}
void Send2(std::uint8_t *buffer, std::uint8_t bufferLengtd) noexcept(
false) // Compliant - unchecked exception not documented
{
// ...
throw InvalidInitParameters("Invalid parameters");
}
See Also
- none
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
dont_document_exception |
Don’t document unchecked exception. |
None |
False |
Options¶
This rule shares the following common options: confidence, 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
autosar_exception_model¶
autosar_exception_model : str = '17_03'
throw_marker¶
throw_marker : str = '@throw'