DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B1018: handler names a predefined check exception

Catalog status: active. Default severity: error. Stable name: handler-for-check. Family: Names and declarations.

Constraint_Error, Program_Error and Storage_Error are what a failed run-time check raises in Ada. Verada proves its checks instead, so in a proved program these exceptions are never raised, and a handler for one would never run. In a build without proof or in advisory mode, a failed check stops the program through Verada's run-time failure policy; it never becomes an exception a handler catches. Handlers and Exceptional_Cases are for the exceptions the program raises itself.

Example (Vada)

   begin
      X := X / Y;
   exception
      when Constraint_Error =>   --  the division is proved instead
         X := 0;
   end;

Example (Varc)

    try {
        X = X / Y;
    } catch Constraint_Error {   // the division is proved instead
        X = 0;
    }

What to do

Make the check pass: test the value first (if Y /= 0 then), or require it in the precondition, and remove the handler. To report a condition to callers, declare an exception of your own and raise it.

Regression source and further reading

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

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