From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: checker@d6.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] assert caught by try with _
Date: Tue, 29 Jul 2003 12:17:52 +0900 [thread overview]
Message-ID: <20030729121752A.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <4.3.2.7.2.20030728192639.025496d8@localhost>
From: Chris Hecker <checker@d6.com>
> >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
next prev parent reply other threads:[~2003-07-29 3:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-28 18:34 Chris Hecker
2003-07-28 19:08 ` Nicolas Cannasse
2003-07-29 2:37 ` Chris Hecker
2003-07-29 3:17 ` Jacques Garrigue [this message]
2003-07-29 21:01 ` Chris Hecker
2003-07-30 10:22 ` Yaron M. Minsky
2003-07-30 15:47 ` james woodyatt
2003-08-06 12:19 ` Michal Moskal
2003-08-06 14:50 ` William Lovas
2003-08-06 17:44 ` Michal Moskal
2003-07-30 5:44 ` Jason Hickey
2003-07-30 5:44 ` [Caml-list] unwind-protect Jason Hickey
2003-07-30 10:30 ` Yaron M. Minsky
2003-07-30 17:29 ` Didier Remy
2003-07-31 0:47 ` Jacques Garrigue
2003-07-30 14:44 ` William Lovas
2003-07-29 22:55 [Caml-list] assert caught by try with _ Martin Berger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030729121752A.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=checker@d6.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox