Is there a way to get GNAT to ensure all exception cases are handled?
To give an example:
package IO renames Ada.Text_IO;
package EIO renames Ada.IO_Exceptions;
procedure Open_File (File : in out IO.File_Type) is
begin
IO.Open (File, IO.In_File, "example.txt");
exception
when EIO.Use_Error =>
IO.Put_Line ("Use!");
when EIO.Device_Error =>
IO.Put_Line ("Device!");
end Open_File;
Open
can also raise Name_Error
so I would like GNAT to warn that case has not been handled.
I found pragma Restrictions (No_Exception_Propagation)
but that seems to apply the check to the standard library calls as well so Open
becomes unusable because it propagates exceptions itself. If I apply this to my example, I get:
14:07: warning: pragma Restrictions (No_Exception_Propagation) in effect
14:07: warning: this handler can never be entered, and has been removed
16:07: warning: pragma Restrictions (No_Exception_Propagation) in effect
16:07: warning: this handler can never be entered, and has been removed
For an example of what I want from another language; Nim has a raises
pragma to annotate what exceptions a procedure can raise, which the compiler enforces. The list can be empty, ie. raises: []
, and the compiler will require that all exceptions will be handled and not propagate. Is there an equivalent to this in Ada?