Path: news.daimi.aau.dk!news.uni-c.dk!newsfeed.sunet.se!news00.sunet.se!sunic!news99.sunet.se!columba.udac.uu.se!news.mdh.se!news.seinf.abb.se!erinews.ericsson.se!eua.ericsson.se!cnn.exu.ericsson.se!newshost.convex.com!news.duke.edu!news.mathworks.com!newsfeed.internetmci.com!in1.uu.net!fu-berlin.de!zrz.TU-Berlin.DE!marie!wpp From: wpp@marie.physik.TU-Berlin.DE (Kai Petzke) Newsgroups: comp.lang.beta Subject: Re: exception in BETA Date: 15 Apr 96 12:50:20 GMT Organization: Technical University Berlin, Germany Lines: 122 Message-ID: References: <3170BD3C.20D7@ifi.uio.no> NNTP-Posting-Host: marie.physik.tu-berlin.de Ola Fosheim Groestad writes: >Russell Mok wrote: >> 1. Exception propagation (to the caller) is not easily supported in >> BETA and basically Knudsen's intention of developing the static >> exception handling was to have a handler independent of the call >> chain. Does anyone find the absence of exception propagation a >> good/bad feature? Why? >Well, as exceptions in Beta seem to be plain virtuals that are bound >I have the following problem. A pattern might provide several >exceptions, some inherited from superpatterns, so if you are only >interested in knowing whether there was an error or not, you really >have to bind all possible errors. I know that this could be >circumvented by clever programming when the classes are designed, but.. > It would have been a lot easier if Beta had a mechanism to "hand-out" >some kind of pattern that described the error, possibly with internal >methods to be called if you want to resume, cancel the original >"request" and a method to be called when you cannot handle the error. Yeah, that would be helpfull. I would like to see a scheme, where a given pattern has only *one* exception virtual, not half a dozen of them, like in the Mjolner file libraries. This might look as follows: exception: (# continue: @boolean; msg: @text; error: (# do false->continue; INNER; 'ERROR\n'->msg.prepend; this(exception); #); notification: error (# do true->continue; INNER #); do INNER; (if not continue then (failure,msg[])->stop if); #); some_pattern: (# catch:< exception (# err1:< error (# do 'Illegal input parameters'->msg; INNER #); err2:< error (# do 'Division by zero'->msg; INNER #); warn1:< notification (# do 'Underflow'->msg; INNER #); do INNER #); ... #); Then you can later call that pattern: l: some_pattern (# catch:: (# err1:: (# leave l #) do 'Some unexpected error occurred:'->putline; msg[]->putline; 'Trying to continue:'->putline; true->continue; #); #) >> 2. Obviously, BETA patten can mimic the dynamic approach, I >> believe it is possible with a feature like LEAVE. Is this correct? >I think there is some limitations on how beta handles leave as for now. >What seems to be the way it is handled is something like this: >L:(# ok:@boolean; >do true->ok; > badfunctioncall(# onerror::(# do false->ok; true->continue #); #); > (if not ok then leave L (* or call an exception in L *) if); >#) The Mjolner compiler has some problems when handling leave/restart of a pattern. However, you can always use a label instead: l: badfunctioncall (# onerror:: (# do leave l #) #); >> 3. How often do you use the mimicked dynamic approach? Do you think it >> should be a built-in feature? >The above way of dealing with it is used often, especially with >file-access. BETA's leave and restart imperatives are dynamic, and unroll the stack, until they find the matching block, which is to be restarted or left. The difference with C++'s catch/try scheme is, that in BETA, you perform the LEAVE or RESTART, when you are sure, which block you want to leave respective restart. So the exception handler itself is just a virtual function call. In C++, you just do a throw, in the hope, that there is someone out there, who catches you. The stack unwinding is performed immediately after the error has been encountered, and before it is decided, how to handle that error. >> 4. Do you think the static approach alone is sufficient and easy >> enough to use? >It might be if it was used differently in the Mjxlner libs. >It puts more load on the library implementor though.. Yeah. Kai -- Kai Petzke, Technical University of Berlin, Germany http://www.physik.tu-berlin.de/~wpp/ to learn about Linux, Postgres and BETA. wpp@marie.physik.tu-berlin.de for regular e-mail How fast can computers get? -- Warp 9, of course, on Star Trek.