Need a catch functionality
Is your capability/feature request related to a problem?
We need to be catch an error, such as overflow, if it happens.
For example the following overflows if Min = integer'low and Max = integer'high
NumInRange := Max - Min + 1 ;
Describe the solution you'd like
Ada uses exceptions. It seems to be able to be localized to the containing code block - such as a procedure.
An Ada example from https://learn.adacore.com/courses/Ada_For_The_CPP_Java_Developer/chapters/10_Exceptions.html
begin
Some_Call;
exception
when Exception_1 =>
Put_Line ("Error 1");
when Exception_2 =>
Put_Line ("Error 2");
when others =>
Put_Line ("Unknown error");
end;
If we wanted to contain it outside of a procedure, it could be included in a sequential block statement, such as
CatchBlock : block
begin
NumInRange := Max - Min + 1 ;
DoSomething(NumInRange, ...) ;
exception
when others =>
report "NumInRange calculation, out of range. Skipping DoSomething" severity ERROR ;
end CatchBlock ;
Ada predefines the named exceptions:
Constraint_Error (which would apply here),
Program_Error (erroneous things caught by compiler),
Storage_Error (not enough memory)