From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,743cbb1eadac54f3 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: question on exceptions Date: 1996/11/06 Message-ID: #1/1 X-Deja-AN: 194898339 references: <55l00n$alv@ash.ridgecrest.ca.us> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-11-06T00:00:00+00:00 List-Id: In article <55l00n$alv@ash.ridgecrest.ca.us>, Do-While Jones wrote: >The moral of the story is that the exception is simply a flag that tells >you something has gone wrong. If you take care to save the pertinent >values before the exception is raised, and if you include a mechanism to >retrieve those values when an exception has been detected, you have all >the information you need. In a multi-tasking program, you would probably want to store this information in a task attribute. I still think that some other languages do it better (more type safety) than Ada. What I want is to declare what sort of information is attached to a particular exception name. Then the handler knows what type of information is attached, and references to this information can be type checked. C++, Java, CLOS, etc have this capability. While your solution works, it isn't quite as safe. For example, a handler for X might try to grab information that is only associated with exception Y. Or somebody might evilly call the function to get the extra information when not in an exception handler at all, when the information isn't available. Or an exception handler might call a procedure that internally raises-then-handles an exception, thus overwriting the information -- you have to be careful to grab the information before doing anything else in the exception handler that might invalidate the information. You could write the information-getting function to detect these errors at run time, but it would be slightly nicer to have compile-time error detection. You can write comments in the code explaining the proper use of this function, but it would be slightly nicer to have that information encoded in the program itself, in a standard way. By the way, during the design of Ada 9X, it was suggested that we have functions for querying things like the Current_Exception_Name and Current_Exception_String. However, the design team rejected this idea for the reasons explained above -- presumably the semantics of calling these at the wrong time would be "erroneous", which is bad. My main complaint about the Ada 95 design for this stuff is that the information associated with an exception *must* be of type String. I suppose you can encode whatever information you want in a string, but not with type safety. - Bob