Path: news.daimi.aau.dk!news.uni-c.dk!newsfeed.sunet.se!news00.sunet.se!sunic!news.sprintlink.net!newsfeed.internetmci.com!swrinde!howland.reston.ans.net!vixen.cso.uiuc.edu!ux5.cso.uiuc.edu!mtravis From: Matthew Travis Newsgroups: comp.object,comp.lang.eiffel,comp.lang.c++,comp.lang.beta,comp.lang.java,comp.lang.sather Subject: Re: What Should An Exception Handling Do? -- Clarification of rules Date: Fri, 22 Mar 1996 04:24:51 -0600 Organization: University of Illinois at Urbana Lines: 51 Message-ID: References: <1996Mar14.155641.4299@schbbs.mot.com> <4irn11$7ln@mimas.brunel.ac.uk> NNTP-Posting-Host: ux5.cso.uiuc.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Sender: mtravis@ux5.cso.uiuc.edu In-Reply-To: <4irn11$7ln@mimas.brunel.ac.uk> Xref: news.daimi.aau.dk comp.object:53070 comp.lang.eiffel:22461 comp.lang.c++:174517 comp.lang.beta:10675 comp.lang.java:27770 comp.lang.sather:12353 H'llo, for clarification, Java uses the same exception handling mechanism as C++ (with the addition of the finally clause). The two possible mechanisms are "resumption" and "termination". A quote from the "Annotated C++ Reference Manual" states: "Exception handling is intended to allow code that has encountered a condition it cannot cope with to return to some other code that directly or indirectly invoked it. There is no way for an exception handler to request the thread of control to resume from the throw point. In other words, "throw" implements the termination model of exception handling." -ARM, Ellis & Stroustrup, page 354 This model has been accepted into the draft C++ standard and is also the model Java uses. The philosophy is that an exception indicates some error condition that is usually unrecoverable and code that is in error should terminate (thinking about it logically). Put another way, an exception will cause the thread of execution to terminate, period, and the exception handler is the place to do cleanup and ensure a graceful exit. If the exception is something that is recoverable, such as a user entering 5/0 in a calculator program, then you should take care of that before an exception is thrown. Exceptions should only be thrown for unhandle-able conditions. Carpe diem, Matthew On 21 Mar 1996, Francesco Fantauzzi wrote: > shang@corp.mot.com (David L. Shang) wrote: > > > > [...] > >But, most exception handling mechanisms focus on the second case, > >which makes exception handling very complicated for recovery. (C++ > >even gives up recovery.) [...] > > ^^^^^------- This isn't really true (if I have understood what you > mean). You can read a dissertation about that in "The Design and > Evolution of C++", by B.S. > > Francesco G. Fantauzzi > > > > > Matthew Travis, mtravis@uiuc.edu http://www.students.uiuc.edu/~mtravis If the while I think on thee, dear friend All losses restored, and sorrows end. -Tennyson