1088 O-O PROGRAMMING AND ADA $33.5 33.5 EXCEPTIONS The STACKS generic package lists two exceptions in its interface:Overflow and Underflow.More generally,you may deal with error conditions by defining arbitrary exception names;Ada also includes predefined exceptions,triggered by the hardware or the operating system,for such cases as arithmetic overflow or exhaustion of memory. Some elements of the Ada exception mechanism were introduced in the chapter on "How not to do it- exceptions,so that we can limit ourselves to a brief examination of how exceptions fit in an Ada example". the Ada approach to software construction. page 415. Simplifying the control structure Exceptions as they exist in Ada are a technique for dealing with errors without impairing the control structure of normal processing.If a program performs a series ofactions,each of which may turn out to be impossible because of some erroneous condition,the resulting control structure may end up looking like actionl; Like others in this chapter,this exam- if errorl then ple follows Ada's error handlingl; use ofthe semicolon as an instruction else terminafor. action2; il error2 then error handling2; else action3. if error3 then error handling3; else The Ada exception mechanism is an effort to fight the complexity of such a scheme -where the elements that perform "useful"tasks sometimes look like a small archipelago in an ocean of error-handling code-by separating the handling of errors from their detection.There must still be tests to determine whether a certain erroneous condition has occurred;but the only action to take then is to raise a certain signal,the exception,which will be handled elsewhere. Raising and handling an exception To raise exceptions rather than handle errors in place,you may rewrite the extract as: actionl; if error/then raise exc/;end: action2;1088 O-O PROGRAMMING AND ADA §33.5 33.5 EXCEPTIONS The STACKS generic package lists two exceptions in its interface: Overflow and Underflow. More generally, you may deal with error conditions by defining arbitrary exception names; Ada also includes predefined exceptions, triggered by the hardware or the operating system, for such cases as arithmetic overflow or exhaustion of memory. Some elements of the Ada exception mechanism were introduced in the chapter on exceptions, so that we can limit ourselves to a brief examination of how exceptions fit in the Ada approach to software construction. Simplifying the control structure Exceptions as they exist in Ada are a technique for dealing with errors without impairing the control structure of normal processing. If a program performs a series of actions, each of which may turn out to be impossible because of some erroneous condition, the resulting control structure may end up looking like action1; if error1 then error_handling1; else action2; if error2 then error_handling2; else action3; if error3 then error_handling3; else … The Ada exception mechanism is an effort to fight the complexity of such a scheme — where the elements that perform “useful” tasks sometimes look like a small archipelago in an ocean of error-handling code — by separating the handling of errors from their detection. There must still be tests to determine whether a certain erroneous condition has occurred; but the only action to take then is to raise a certain signal, the exception, which will be handled elsewhere. Raising and handling an exception To raise exceptions rather than handle errors in place, you may rewrite the extract as: action1; if error1 then raise exc1; end; action2; “How not to do it — an Ada example”, page 415. Like others in this chapter, this example follows Ada’s use of the semicolon as an instruction terminator