No Use of "others" in Exception Handlers (RPP05)
Level \(\rightarrow\) Required
- Category
- Safety:
\(\checkmark\)
- Cyber:
\(\checkmark\)
- Goal
- Maintainability:
\(\checkmark\)
- Reliability:
\(\checkmark\)
- Portability:
\(\checkmark\)
- Performance:
- Security:
Remediation \(\rightarrow\) Low
Verification Method \(\rightarrow\) GNATcheck rule:
OTHERS_In_Exception_Handlers
(builtin rule)
Reference
N/A
Description
Much like the situation with others
in
case
statements and case
expressions, the use of others
in exception handlers makes it
possible to omit an intended specific handler for an exception, especially
a new exception added to an existing set of handlers. As a result, a
subprogram could return normally without having applied any recovery for
the specific exception occurrence, which is likely a coding error.
Applicable Vulnerability within ISO TR 24772-2
N/A
Applicable Common Weakness Enumeration
Noncompliant Code Example
procedure Noncompliant (X : in out Integer) is
begin
X := X * X;
exception
when others =>
X := -1;
end Noncompliant;
Compliant Code Example
procedure Compliant (X : in out Integer) is
begin
X := X * X;
exception
when Constraint_Error =>
X := -1;
end Compliant;
Notes
ISO TR 24772-2: 6.50.2 slightly contradicts this when applying exception handlers around calls to library routines:
Put appropriate exception handlers in all routines that call library routines, including the catch-all exception handler
when others =>
Put appropriate exception handlers in all routines that are called by library routines, including the catch-all exception handler
when others =>
ISO TR 24772-2 also recommends "All tasks should contain an exception handler at the outer level to prevent silent termination due to unhandled exceptions."