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 EAA03247; Wed, 12 Mar 2003 04:25:08 +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 EAA03412 for ; Wed, 12 Mar 2003 04:25:07 +0100 (MET) Received: from psyche.kaba.or.jp (psyche.kaba.or.jp [202.249.19.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2C3P5f28520 for ; Wed, 12 Mar 2003 04:25:05 +0100 (MET) Received: from mail.kaba.or.jp (cascade.kaba.or.jp [202.249.19.34]) by psyche.kaba.or.jp (Postfix) with ESMTP id EC9E3229C1 for ; Wed, 12 Mar 2003 12:25:03 +0900 (JST) Received: from WARP (dhcp04.kaba.or.jp [202.249.19.39]) by mail.kaba.or.jp (Postfix) with SMTP id B79CE49A6D for ; Wed, 12 Mar 2003 12:25:03 +0900 (JST) Message-ID: <01d601c2e846$dbeef2e0$2713f9ca@WARP> From: "Nicolas Cannasse" To: References: <46D5FE1E.20DB90B0.00958B05@netscape.net> Subject: Re: [Caml-list] Checked exceptions and type inference Date: Wed, 12 Mar 2003 12:24:15 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 inference:01 openfile:01 compiler:01 ocaml:01 nicolas:01 null:01 match:02 exception:02 string:03 explicitly:03 exn:03 btw:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Perhaps I don't understand what migth be a > 'checked exception' in ML. I am missing something?. > can you explain it with an example Checked exception are like in Java : the compiler warn you if you don't catch them, and if you really don't want to do so, you have to put an annotation on your fonction to say that it is throwing this kind of exception. For example File openFile( String filename ) { return new File(filename); } compiler warn you about the IOException that can be thrown by the call to "new File" and so you have either to ignore it : File openFile( String filename ) { try { return new File(filename); } catch( IOException e ) { // print it if you feel like return null; } } or to propagate it explicitly File openFile( String filename) throws IOException { return new File(filename); } but then the calling function of openFile will have also to decide either to catch or to throw the IOException. That's quite a rigorous way of handling exceptions, and you can use the RuntimeException class to use exceptions à la OCaml. BTW, I really dislike checked Exceptions, but I realy you want to support them, here's some tip : type 'a checked = | Result of 'a | Exc of exn let check f x = try Result ( f x ) with e -> Exc e and then you can use it like this when you catch the exception : let open_file filename = match check open_out filename with | Result x -> x | Exc e -> (* do something *) or when you want to propagate it : let open_file filename = check open_out filename Nicolas Cannasse ------------------- 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