Runtime Error (Exception) Handling

ADA handles programmer defined exceptions and system defined exceptions

Some of the system defined exceptions are like 
  1. NUMERIC_ERROR – raised whenever the abnormal precision in the program like divide by zero 
  2. STORAGE-ERROR – raised whenever the program runs out of memory space
  3. CONSTRAINT_ERROR – asserts when a variable goes out of its bound
  4. TASKING_ERROR – raised during the incorrect use of tasks
  5. PROGRAM_ERROR- raised whenever an exception is not captured by any other conditions
Example on Exceptions

//Program to create two programmer defined exceptions

    if P<100>
    elseif P>150 then 
end if;
end loop;

when LOW_PRESSURE => put(“Warning: Very Low Pressure”);
when HIGH_PRESSURE => put (“Warning: High Pressure”);

  • When exceptions are raised in multiple procedures or block and Procedures, handling the exceptions can be done using any of the procedure 
  • For Example, If there are three procedures X,Y and Z. X calls Y and Y calls Z, now there is an exception at Z (which does not have exception handler), the control will transfer the previous procedure Y (Which contains the exception handling mechanism) and handled over there.
  • Similary if a block does not have an exception handler, then the procedure which includes the block handles the expection , if that procedure contains the exception handler

Leave a Reply