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