bpendlet@esunix.UUCP (02/06/87)
Could we get a discussion going on exception handling in Modula-2? The lack of a defined exception handling mechanism in the language is, in my opinion, a serious flaw in the language. Rather like a flaw in a diamond. I've read that C's setjmp and longjmp have been implemented and used with some versions of Modula-2, and I've seen the description of exception handling in Modula-2+ described in "Extending Modula-2 to Build Large Integrated Systems" in the November, 1986 edition of IEEE Software. I'm interested in how people have done exception handling in systems they have written in Modula-2 and what exception handling mechanisms have been implemented in other versions of Modula-2. If there is a reason why exception handling was left out of Modula-2 I'd like to hear that too. Thanks Bob Pendleton -- --- Bob Pendleton Evans & Sutherland Computer Corporation UUCP Address: {decvax,ucbvax,ihnp4,allegra}!decwrl!esunix!bpendlet Alternate: {ihnp4,seismo}!utah-cs!utah-gr!uplherc!esunix!bpendlet hacking code, hacking code. sometimes happy, sometimes bored, almost lost in a pile of spode. tell the people "I'm only hacking code." --- I am solely responsible for what I say. ---
"Michael_M_Cashen.SBDERX"@XEROX.COM.UUCP (02/09/87)
Ref: Could we get a discussion going on exception handling in Modula-2? The lack of a defined exception handling mechanism in the language is, in my opinion, a serious flaw in the language. Rather like a flaw in a diamond. If there is a reason why exception handling was left out of Modula-2 I'd like to hear that too Bob, Correct me if I am wrong but from my observations of Modula-2, I think the reason why explicit exception handling mechanisms do not exist is mainly because it was designed under the auspice of "Structured Programming". This consists mechanisms such as iteration, sequence and decision but also includes recommendations on functionality such as "Single input, single output" (i.e. lowest level of functionality for any given procedure) structures such as the infamous GOTO statements for induced flow control are not recommended (other than exiting from long loops, etc.) In my opinion then, I consider that given the above criteria it would not be pertinent for the famed designer of modula 2 (a strong advocate of structured techniques) to introduce the digressive mechanisms of exception handlers, which in some instances actually include such things as GOTO statements. ( A major bottom smackable offence in some quarters). Then again I may be completely wrong on this subject, so I await confirmation or will stand corrected. IF Modula_2 AND exception_Handlers THEN Ada OR Mesa; Mike GOTO Bob IF NOT Finished ELSE Mike; RETRY;
bobc@tikal.UUCP (02/11/87)
Summary: I would like to see a much more involved discussion on how to implement exceptions in the language as it exists now. I feel that something useful can be worked out. So I hope to inspire some creative discussion by submitting the following exception handling module. I have not yet had the chance to implement it, but I feel that all but the last three routines can be implemented in the language as it exists now, with out adding any new features. The last three routines are mostly the "C" setjmp/longjmp, or the LISP catch/throw, I used the LISP names to set them apart from the "C" routines. I believe that about a year ago someone else proposed something of this form, but I can't find the article. I also admit that there are some advantages to implementing the constructs in the language it's self. They mostly relate to scoping for example: With my module you could write: IMPORT StringOverFlow; (* An EXCEPTION defined and set up else where *) ... BEGIN ... Handle(StringOverFlow,MyHandler); ...call some string routines that use StringOverFlow... FreeHandler(StringOverFlow); ... With a Ada you could write: -- StringOverFlow is defined else where and imported USE/WITH??? begin ...call some strings routines that use StringOverFlow... exception when StringOverFlow => if not MyHandler(StringOverFlow) then raise; end if; end ...; I feel that both implementations do the same work, however the Ada method does many things automaticly for you based on the nesting factor. It in effect automaticly calls FreeHandler when you exit the current block. This note is getting a little bit long, so I will stop and let people flame at me as per usual. Then when I know what the complaints are I will correct/defend myself. Bob Campbell Teltone Corporation 18520 - 66th AVE NE P.O. Box 657 Seattle, WA 98155 Kirkland, WA 98033 bobc@tikal.teltone.com {amc,dataio,fluke,hplsla,sunup,uw-beaver}!tikal!bobc tikal!bobc@beaver.cs.washington.EDU Module Exceptions.DEF included below: -------------------------------------------------------------- DEFINITION MODULE Exceptions; TYPE EXCEPTION; ExceptionHandler = PROCEDURE (EXCEPTION):BOOLEAN; (* A exception handler is passed the exception as a argument * so that it can find out (via comparing) what exception was * caught *) PROCEDURE NewException(VAR X:EXCEPTION;DefaultHandler:ExceptionHandler); (* Create a new exception with a default handler * Should a default handler be do nothing or halt? *) (* Some optional Default handlers *) PROCEDURE Ingore(VAR X:EXCEPTION):BOOLEAN; (* always returns true causes exception to be ingored *) PROCEDURE Abort(VAR X:EXCEPTION):BOOLEAN; (* always calls HALT *) PROCEDURE Handle(X:EXCEPTION;Handler:ExceptionHandler); (* Set up a handler this pushes the previous handler onto a * Stack so that when FreeHandler is called it reverts to the * previous Handler. *) PROCEDURE FreeHandler(X:EXCEPTION); (* frees up the current handler, if the current handler is the * default handler nothing happens. *) PROCEDURE Raise(X:EXCEPTION); (* call the handlers for the passed exception. The handlers are * called in reverise order until one of the handlers return TRUE * to indicate that it has handled the exception. *) (* Now onto the optional low level routines a type of setjmp/longjmp * as in C, but I desided to use the LISP function names Catch, and * Throw *) TYPE Ball; (* Lets play catch with the ball :-) :-) *) (* This might be too cute a name :-) :-) *) PROCEDURE Catch(VAR what:Ball):BOOLEAN; (* This function returns TRUE when it is thrown to, FALSE * when it is first set up *) PROCEDURE Throw(what:Ball); (* jumps to that last call to Catch for this "Ball" restores * that stack frame, and causes it to apear that Catch returned * true *) PROCEDURE FreeCatcher(VAR what:Ball); (* sets up the Ball such that attempting to Throw it will cause * a halt *) END Exceptions.