Unformatted text preview:

Exception Handling Copyright 1999 CS655 Paul F Reynolds Jr Exception Handling Considerations What constitutes an exception Domain Range errors Cristian Omission output not there Timing Too early too late Response wrong output Crash no response When an exception is raised how far can it propagate What chain does an exception follow static dynamic Copyright 1999 CS655 Paul F Reynolds Jr Exception Handling Considerations What to do with exception raiser Resume for certain NOTIFY Resume at handler s option SIGNAL Terminate ESCAPE Should exceptions have parameters Should passed over routines be allowed to cleanup How should exceptions be handled in parallel environment Copyright 1999 CS655 Paul F Reynolds Jr CLU Exception Handling What is an exception User defined failure Propagation To caller only except failure Path searched for handler Dynamic chain What to do with raiser Terminate Parameters Yes Declare exceptions thrown Yes Clean up N A no by default How handled in parallel N A Copyright 1999 CS655 Paul F Reynolds Jr Ada Exception Handling What is an exception User defined 4 5 system defined Propagation To caller Path searched for handler Dynamic chain What to do with raiser Terminate Parameters No Declare exceptions thrown No Clean up N A no by default How handled in parallel environment Copyright 1999 Not propagated CS655 Paul F Reynolds Jr Yemini Berry Exception Handling What is an exception User defined Propagation To caller Path searched for handler Dynamic chain What to do with raiser User choice replacement model Parameters Yes Declare exceptions thrown Yes Clean up Yes How handled in parallel environment N A Copyright 1999 CS655 Paul F Reynolds Jr C Exception Handling What is an exception User defined Propagation Thrown to catcher Path searched for handler Dynamic chain What to do with raiser Terminate Parameters Yes Declare exceptions thrown No Clean up Yes How handled in parallel environment N A Copyright 1999 CS655 Paul F Reynolds Jr Java Exception Handling What is an exception User defined Propagation Thrown to catcher Path searched for handler Dynamic chain What to do with raiser Terminate Parameters Yes Declare exceptions thrown Yes Clean up Yes How handled in parallel environment N A Copyright 1999 CS655 Paul F Reynolds Jr Raising Exceptions CLU and Ada Explicit Raising CLU signal IF x 0 THEN SIGNAL neg X Ada raise Termination in both cases IF x 0 THEN RAISE neg Implicit Raising CLU systems failures failure to catch Ada four Ada95 five in Ada83 predefined failures tasking program storage constraint numeric X d in Ada95 Ada supports exception raising during elaboration Copyright 1999 CS655 Paul F Reynolds Jr Raising Exceptions C and Java Explicit Raising Throw catch Implicit Raising C runtime error range error overflow error underflow error bad alloc bad cast All built off base class exception Java built in hierarchy with base throwable extensive set of exceptions AbstractMethodError InternalError UnknownError InterruptedException EmptyStackException IOException floats don t throw exceptions Copyright 1999 CS655 Paul F Reynolds Jr Sample CLU Function sign proc x int returns int signals zero neg int if x 0 then signal neg x elseif x 0 then signal zero else return x end Note Java like requirement end sign to name exceptions that can be thrown Of course CLU had the requirement first Copyright 1999 CS655 Paul F Reynolds Jr Sample Ada Function Package STACK is ERROR exception procedure push x integer function pop return integer end STACK package body STACK is function POP return integer is begin if top 0 then raise ERROR end if top top 1 return s top 1 end POP end STACK Copyright 1999 CS655 Paul F Reynolds Jr Handling Exceptions CLU CLU statement level a sign x EXCEPT WHEN neg i int handle a sign x sign y EXCEPT WHEN neg i int Who raised BEGIN s1 EXCEPT WHEN EXIT done s2 END EXCEPT WHEN excp1 H1 done H2 Can raise another exception in same procedure using Exit Copyright 1999 CS655 Paul F Reynolds Jr Handling Exceptions Ada Ada frame level BEGIN s1 s2 EXCEPTION WHEN EXCP1 H1 raise WHEN EXCP2 H2 END elaboration level DECLARE elaborated stuff exceptions handled by invoker BEGIN s1 exceptions handled in frame EXCEPTION WHEN EXCP1 H1 END Copyright 1999 CS655 Paul F Reynolds Jr Propagating Exceptions CLU and Ada CLU to invoker through explicit means Except for failure exception propagation is explicit only Procedure specifications include ID s of signalled exceptions coupling between called procedures and all potential callers Ada to end of frame statements to invoker elaborations Exceptions propagate up dynamic call chain by default until caught interesting interaction with static scoping name passed out of scope and back in again Copyright 1999 CS655 Paul F Reynolds Jr CLU Failure Initiation nonzero proc x int returns int return sign x except when neg y int return y end zero exception goes uncaught end nonzero Failure unhandled exception zero gets propagated Copyright 1999 CS655 Paul F Reynolds Jr package D is procedure A Ada Propagation procedure B end procedure OUTSIDE is begin D A end OUTSIDE package body D is ERROR exception procedure A is begin raise ERROR end A Call to D B can create interesting procedure B is begin situation OUTSIDE exception when ERROR end B end D Copyright 1999 CS655 Paul F Reynolds Jr CLU s Failure Exceptions Only automatically propagated exception is failure raised if no handler for raised named exception can be explicitly raised occurs if unanticipated failure occurs thoughts about overloading of failure thoughts about propagating failure rather than name Ada Copyright 1999 CS655 Paul F Reynolds Jr Parameters CLU Yes See Yemini and Berry for argument in favor Ada No not even Ada95 result is Ada can require access to non locals to straighten things out could lead to erroneous programming determining parameter passing mechanism C Yes Java Yes Copyright 1999 CS655 Paul F Reynolds Jr Problem with No Parameters PROC P inout param1 param2 BEGIN EXCEPTION WHEN excp1 END Possible messing with non locals to determine if acceptable values have been set Copyright 1999 CS655 Paul F Reynolds Jr Level of Application CLU Java statement level Ada C x a b c Because of operator overloading functions that redefine operations can do their own repairs having an in expression effect Copyright 1999 CS655 Paul F Reynolds Jr Ada and Tasking Errors T2 T1 Accept E do T2 E Copyright 1999 END CS655 Paul F Reynolds Jr Ada and Tasking Errors Exception raised inside accept no


View Full Document

UVA CS 655 - Exception Handling

Download Exception Handling
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exception Handling and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exception Handling and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?