Post · 1 min read· pp. 272–273

Do Not Raise Language-Defined Exceptions (EXU01)

Level →\rightarrow Required

Category : Safety: : ✓\checkmark

code
Cyber:
:   ✓\checkmark

Goal : Maintainability: : ✓\checkmark

code
Reliability:
:   ✓\checkmark

Portability:
:   ✓\checkmark

Performance:

Security:

Remediation →\rightarrow Low

Verification Method →\rightarrow GNATcheck rule: Raising_Predefined_Exceptions (builtin rule)

Reference

[SEI-Java] ERR07-J

Description

In no case should the application explicitly raise a language-defined exception.

The Ada language-defined exceptions are raised implicitly in specific circumstances defined by the language standard. Explicitly raising these exceptions would be confusing to application developers. The potential for confusion increases as the exception is propagated up the dynamic call chain, away from the point of the raise statement, because this increases the number of paths and thus corresponding language-defined checks that could have been the cause.

Applicable Vulnerability within ISO TR 24772-2

N/A

Applicable Common Weakness Enumeration

Noncompliant Code Example

ada
procedure Noncompliant (X : in out Integer) is
begin
   if X < Integer'Last / 2
   then
      X := X * 2;
   else
      raise Constraint_Error;
   end if;
end Noncompliant;

Compliant Code Example

ada
procedure Compliant (X : in out Integer) is
begin
   if X < Integer'Last / 2
   then
      X := X * 2;
   else
      raise Math_Overflow;
   end if;
end Compliant;

Notes

N/A