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 FAA08247; Tue, 29 Jul 2003 05:18:01 +0200 (MET DST) 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 FAA07342 for ; Tue, 29 Jul 2003 05:17:59 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h6T3Hvf00453 for ; Tue, 29 Jul 2003 05:17:57 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2/3.7W) with ESMTP id MAA17443; Tue, 29 Jul 2003 12:17:52 +0900 (JST) To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] assert caught by try with _ In-Reply-To: <4.3.2.7.2.20030728192639.025496d8@localhost> References: <4.3.2.7.2.20030728112622.02f3fef8@localhost> <00d301c3553b$9c01f030$ca00a8c0@warp> <4.3.2.7.2.20030728192639.025496d8@localhost> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030729121752A.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 29 Jul 2003 12:17:52 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; jacques:01 caml-list:01 hecker:01 checker:01 ignoring:01 runtime:01 specifics:01 debugging:01 camlp:01 chris:01 ocaml:01 assertions:01 garrigue:01 behaviour:01 assert:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris Hecker > >You could tell the same for stack overflow and some other kinds of > >exceptions. OCaml uniformly treat failures as exceptions, and that's the > >right thing to do. But catching exceptions with _ , without even printing > >them, is not the "right thing" and is definitly huge pain and error prone. > > I totally disagree about assert being the same as a stack overflow in > nature, but more importantly, you're ignoring the lessons learned from C++ > and Java on the exception specification front. You just don't know what > exceptions code you call in a real program will throw in general. There > are plenty of times when you want to try something at runtime and just bail > if it doesn't work, and you don't care about the specifics of why it didn't > work. A single "with _" will mask any assertions living below it, which > seems to me to be a bad thing since by definition an assert is a > development debugging tool. Assert should just blow up, like in C (at > least as an option). You shouldn't have to remember to put a "with" clause > in for it. But you might really want to catch assert failures! For instance if you're building a debugging tool. So the problem rather stems from the fact exn is a flat type. You have no way to specify "categories" of exceptions, like you would do in Java. Also you could view the behaviour of [try ... with _ -> ...] as dangerous, and prefer a different behaviour. Unfortunately, _ is expected to mean any exception, and it would be difficult to make it mean something else. Note that it's easy enough to define a class of exceptions as fatal: let check_fatal = function Assert_failure _ | Stack_overflow | Match_failure _ as exn -> raise exn | _ -> ();; Then you just have to write try ... with exn -> check_fatal exn; ... You can certainly use camlp4 to do this automatically. Alternatively, one could argue that this is similar to the ctrl-break problem: [Sys.catch_break] allows you to decide whether you want it to be catchable or not. Unfortunately this would imply some extra cost for [raise]. Jacques ------------------- 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