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=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,d4b13594b8779b99 X-Google-Attributes: gid103376,public From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) Subject: Re: Improving Ada Exceptions Date: 1997/11/03 Message-ID: <63jqd0$21p$1@goanna.cs.rmit.edu.au>#1/1 X-Deja-AN: 287547859 References: <63072n$q6r$1@berlin.infomatch.com> Organization: Comp Sci, RMIT University, Melbourne, Australia. Keywords: exceptions NNTP-Posting-User: ok Newsgroups: comp.lang.ada Date: 1997-11-03T00:00:00+00:00 List-Id: blaak@infomatch.com (Ray Blaak) writes: >Hello all. I am an Ada fanatic who has just started his first C++ project. >Being thoroughly ingrained against the evils of C++ I was quite surprised to >find it not as bad as I expected. There are many horrible aspects about it, to >be sure, but one thing I find very cool is C++'s exception mechanism. Does anyone know whether C++ copied the idea of throwing an object from CLOS? The 'condition system' in Common Lisp goes back a long way. Maybe the idea of throwing objects is just obvious. Of course, there _is_ the wee problem of running a constructor so you can throw a 'storage exhausted' exception, but a few prebuilt exceptions will fix that. >It is a very powerful thing to be able to throw and catch arbitrary objects, It is also rather 'heavyweight' for a lot of situations. There's another problem. What if an exception object belongs to a class that was declared inside a subprogram P, and no handler inside P catches it. Now an object has escaped outside the region of the program where it makes sense. Imagine, for example void foo(void) { char buff[4]; class my_exception : std :: bad_alloc { private: char *msg; public : myexception(char *m) msg(m) {} }; strcpy(buff, "fu!"); my_exception e(buff); throw buff; } This is not supposed to be correct C++, by the way, just to illustrate the possibility. C++ puts severe restrictions on classes declared inside functions (which is a rather gross violation of one Stroustrup's design rules for C++: allow nesting whenever it makes sense). Ada, however, doesn't have those silly restrictions, which means that throwing an exception object out of the scope of its class would be a possibility that would have to be blocked some way. Lisp, of course, makes returning objects outside their lexical scope _work_, so the problem doesn't apply in quite these terms to CLOS. -- John �neas Byron O'Keefe; 1921/02/04-1997/09/27; TLG,TLTA,BBTNOTL. Richard A. O'Keefe; RMIT Comp.Sci; http://www.cs.rmit.edu.au/%7Eok