DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B5111: raise might be reached

Catalog status: active. Default severity: error. Stable name: raise-reachable. Family: Contracts and termination.

A raise (Varc throw) that no handler takes and the subprogram's Exceptional_Cases do not list is allowed only where the prover shows it is never reached: the program's other checks and contracts rule it out. The same goes for an exception a call propagates that nothing takes. A run without proof (--no-prove) reports the same code when one is reached.

Example (Vada)

   function Half (N : Integer) return Integer is
     (if N mod 2 = 0 then N / 2 else raise Constraint_Error);   --  Half (3) raises

Example (Varc)

    fn half(n: Integer) -> Integer = if n %% 2 == 0 { n / 2 } else { throw Constraint_Error };

What to do

Add a precondition or an earlier check that excludes the values reaching the raise (with Pre => N mod 2 = 0), or deal with the case without raising. This example cannot be repaired by catching Constraint_Error (B1018), and a function cannot declare propagated exceptional cases. For a user-declared exception in a supported procedure, a matching handler or an appropriate Exceptional_Cases contract can instead describe the intended application outcome. See exception propagation.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See contracts and termination, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.