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 TAA28097; Wed, 12 Mar 2003 19:28:11 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA27700 for ; Wed, 12 Mar 2003 19:28:10 +0100 (MET) Received: from www.paneris.org ([213.2.103.31]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id h2CISAf19043 for ; Wed, 12 Mar 2003 19:28:10 +0100 (MET) Received: (qmail 14943 invoked by uid 502); 12 Mar 2003 18:45:58 -0000 Date: 12 Mar 2003 18:45:58 -0000 Message-ID: <20030312184558.14942.qmail@www.paneris.org> From: William Chesters To: caml-list@inria.fr In-Reply-To: Subject: [Caml-list] Checked exceptions and type inference X-Spam: no; 0.00; chesters:01 williamc:01 paneris:01 caml-list:01 inference:01 monomorphic:01 foo:01 interacts:01 debugger:01 ocaml:01 irrelevant:01 int:01 writes:01 polymorphic:01 checking:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Brian Hurt writes: > Is there any research on using checked exceptions in an ML derived > language? Any plans/opinions on implementing checked exceptions in Ocaml? Java checked exceptions are a huge pain because the checking is too monomorphic. Here's a trivial example: int numElements(Enumeration e) { for (int i = 0; e.hasMoreElements(); ++i) e.nextElement(); } System.out.println(numElements(new LinesInFileEnumeration("foo.txt")); This fails because LinesInFileEnumeration wants to throw IOException, while the Enumeration interface won't let it. To work around this you have to -- explicitly catch and re-wrap exceptions into some form acceptible for the interface you want to implement, at more or less every package boundary (not only boring but also functionally bad--- what am I supposed to do with a wrapped exception? how can I tell at a higher level that it is really an IOException? and it really interacts badly with the debugger ...) or make practically every method in your program able to throw practically any exception. Much real Java code ends up this way, with methods throwing apparently irrelevant IOExceptions and SQLExceptions left right and centre. The infection spreads very quickly. or make all your exceptions RuntimeExceptions. This is actually the best solution---bypass the "checked exception" system entirely. Maybe a more polymorphic kind of exception "type checking" would be less annoying, but I also don't think it would really achieve anything. ------------------- 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