From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA03669; Sat, 28 Aug 2004 11:24:15 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA04135 for ; Sat, 28 Aug 2004 11:24:14 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i7S9OCIj020846; Sat, 28 Aug 2004 11:24:13 +0200 Received: from [192.168.1.200] (ppp212-216.lns2.syd3.internode.on.net [203.122.212.216]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i7S9O84Y088891; Sat, 28 Aug 2004 18:54:09 +0930 (CST) Subject: Re: [Caml-list] C++ Throws From: skaller Reply-To: skaller@users.sourceforge.net To: Xavier Leroy Cc: David McClain , Brian Hurt , caml-list In-Reply-To: <20040828081743.GA1229@yquem.inria.fr> References: <000901c48c93$9bc9eec0$0201000a@dylan> <1093657249.15255.1712.camel@pelican.wigram> <001201c48cb5$73239ee0$0401000a@dylan> <20040828081743.GA1229@yquem.inria.fr> Content-Type: text/plain Message-Id: <1093685048.15255.1795.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 28 Aug 2004 19:24:08 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41304F3C.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 unwind:01 run-time:01 exemplified:01 modula-:01 prolog:01 unwind:01 converge:01 stacked:01 fifo:01 catch-all:01 catch-all:01 python:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 2004-08-28 at 18:17, Xavier Leroy wrote: > There are indeed two "schools" of exception handling: one that unwind > stack frames one by one until an exception handler is found, and one > that maintains at run-time a chaining between exception handling > blocks on the stack, so that no stack searching is necessary when an > exception is thrown. > > The first school is exemplified by C++, Modula-3, Java and C#; the > second school by Lisp, Caml and to some extent Prolog (if you view > backtracking as a generalization of exception handling). C++ is required by the ISO Standard to unwind each frame to the handler, executing destructors in FILO order. Ocaml doesn't need to do that, it has a garbage collector which finalises blocks out of order. > The two approaches have very different performance trade-offs. To > make things worse, many people from the first school are not even > aware of the second approach. So, as usual, there is no hope to see > the world converge on a single exception mechanism. As above -- for C++ it is tied up with the requirement to execute destructors of stacked objects in a FIFO manner. Simply dropping back to the handler isn't an option. So it isn't necessarily ignorance that will prevent convergence -- there are distinct architectural models to consider, in this finalisation in C++ must be FILO in both normal and exceptional exits -- C++ code is allowed to rely on destructors executing in reverse order to constructors. > > How in the world would any kind of cross-language > > interoperability ever function if this were the case. The C++ committee was only ever concerned with C interoperability. Its not their job to consider other languages, especially ones that do not have ISO Standards backing them, where inter-committee liason is impossible. > For the reverse direction (Caml calling C++), I'm afraid the only > solution is to use a C++ catch-all clause to turn C++ exceptions into > Caml exceptions. Which can't be done in a portable manner: since the catch-all cannot have an associated static type, you can't actually refer to the exception object in the handler. Other languages -- Java and now Python -- have a top level exception type from which all exceptions must be derived. In C++, the type doesn't even have to be polymorphic -- you can throw an int or string if you want. Perhaps that's stupid but the reason is compatibility with earlier C++ code which typically threw int or char *. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners