* Re: [Caml-list] assert caught by try with _
@ 2003-07-29 22:55 Martin Berger
0 siblings, 0 replies; 12+ messages in thread
From: Martin Berger @ 2003-07-29 22:55 UTC (permalink / raw)
To: caml-list
> you're ignoring the lessons learned from C++ and Java on
> the exception specification front.
ok, i'll bite. what are these lessons? that exception specifications
are not a good thing?
martin
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Caml-list] assert caught by try with _
@ 2003-07-28 18:34 Chris Hecker
2003-07-28 19:08 ` Nicolas Cannasse
2003-07-30 5:44 ` Jason Hickey
0 siblings, 2 replies; 12+ messages in thread
From: Chris Hecker @ 2003-07-28 18:34 UTC (permalink / raw)
To: caml-list
Is the the "right thing" for assert to be caught by a try ... with _ -> ...
block? In other words, it seems like you want an assert to always blow up
if asserts are turned on, not to fail silently when there's a try block
somewhere higher up in the program. Maybe it should be an option to have
it fail immediately regardless of whether there's an exception handler
around it? The problem is that the workaround is to muck with every "with"
expression to ensure you don't accidentally catch an assert, which is a
huge pain and error prone, so it seems easier to have an option to just
blow up. The rationale is that asserts are meta, not part of the main
program's flow.
I just got bitten by this and spent a couple hours trying to figure out why
my program silently stopped working.
Thanks,
Chris
# let _ = try assert false with _ -> ();;
- : unit = ()
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-28 18:34 Chris Hecker
@ 2003-07-28 19:08 ` Nicolas Cannasse
2003-07-29 2:37 ` Chris Hecker
2003-07-30 5:44 ` Jason Hickey
1 sibling, 1 reply; 12+ messages in thread
From: Nicolas Cannasse @ 2003-07-28 19:08 UTC (permalink / raw)
To: caml-list, Chris Hecker
> Is the the "right thing" for assert to be caught by a try ... with _ ->
...
> block? In other words, it seems like you want an assert to always blow up
> if asserts are turned on, not to fail silently when there's a try block
> somewhere higher up in the program. Maybe it should be an option to have
> it fail immediately regardless of whether there's an exception handler
> around it? The problem is that the workaround is to muck with every
"with"
> expression to ensure you don't accidentally catch an assert, which is a
> huge pain and error prone, so it seems easier to have an option to just
> blow up. The rationale is that asserts are meta, not part of the main
> program's flow.
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.
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-28 19:08 ` Nicolas Cannasse
@ 2003-07-29 2:37 ` Chris Hecker
2003-07-29 3:17 ` Jacques Garrigue
0 siblings, 1 reply; 12+ messages in thread
From: Chris Hecker @ 2003-07-29 2:37 UTC (permalink / raw)
To: Nicolas Cannasse, caml-list
>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.
Chris
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-29 2:37 ` Chris Hecker
@ 2003-07-29 3:17 ` Jacques Garrigue
2003-07-29 21:01 ` Chris Hecker
0 siblings, 1 reply; 12+ messages in thread
From: Jacques Garrigue @ 2003-07-29 3:17 UTC (permalink / raw)
To: checker; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-29 3:17 ` Jacques Garrigue
@ 2003-07-29 21:01 ` Chris Hecker
2003-07-30 10:22 ` Yaron M. Minsky
2003-08-06 12:19 ` Michal Moskal
0 siblings, 2 replies; 12+ messages in thread
From: Chris Hecker @ 2003-07-29 21:01 UTC (permalink / raw)
To: Jacques Garrigue; +Cc: caml-list
>But you might really want to catch assert failures!
>For instance if you're building a debugging tool.
Okay, but it seems like a compile time switch would serve both
interests. Plus, it seems like the "assert should blow up" usage would be
far more common, since the number of people writing non-debugging-tool code
is far larger than the number writing debugging tool code.
Another way of thinking about this is that almost everybody re-#defines
assert in production C/C++ programs to do their own assert handling during
development (whether it's printing out additional information, allowing you
to drop into the debugger, popping up a message box, sending bug email,
whatever). With assert hard-coded into ocaml, you can't do this. I could
use a different function than assert, but then it won't compile out,
etc. I could use camlp4 to make my own assert, but then I take a
compilation speed hit on all my files, etc.
Anyway, it sounds like this behavior isn't surprising to anybody else, so
I'll add it to the list of things that only I think are broken about ocaml. :)
Chris
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
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
1 sibling, 1 reply; 12+ messages in thread
From: Yaron M. Minsky @ 2003-07-30 10:22 UTC (permalink / raw)
To: Caml List
On Tue, 2003-07-29 at 17:01, Chris Hecker wrote:
> >But you might really want to catch assert failures!
> >For instance if you're building a debugging tool.
>
> Okay, but it seems like a compile time switch would serve both
> interests. Plus, it seems like the "assert should blow up" usage would be
> far more common, since the number of people writing non-debugging-tool code
> is far larger than the number writing debugging tool code.
>
> Another way of thinking about this is that almost everybody re-#defines
> assert in production C/C++ programs to do their own assert handling during
> development (whether it's printing out additional information, allowing you
> to drop into the debugger, popping up a message box, sending bug email,
> whatever). With assert hard-coded into ocaml, you can't do this. I could
> use a different function than assert, but then it won't compile out,
> etc. I could use camlp4 to make my own assert, but then I take a
> compilation speed hit on all my files, etc.
>
> Anyway, it sounds like this behavior isn't surprising to anybody else, so
> I'll add it to the list of things that only I think are broken about ocaml. :)
Not so fast. I have hit the same issue and entirely agree. In general,
the issue of making sure that an exception escapes when you want it to
is a bit of a problem, and it would be nice to have some way of dealing
with this, and not just with asserts. But certainly asserts should have
the option for the kind of always-die behavior you're talking about.
y
--
|--------/ Yaron M. Minsky \--------|
|--------\ http://www.cs.cornell.edu/home/yminsky/ /--------|
Open PGP --- KeyID B1FFD916 (new key as of Dec 4th)
Fingerprint: 5BF6 83E1 0CE3 1043 95D8 F8D5 9F12 B3A9 B1FF D916
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-30 10:22 ` Yaron M. Minsky
@ 2003-07-30 15:47 ` james woodyatt
0 siblings, 0 replies; 12+ messages in thread
From: james woodyatt @ 2003-07-30 15:47 UTC (permalink / raw)
To: The Trade
On Wednesday, Jul 30, 2003, at 03:22 US/Pacific, Yaron M. Minsky wrote:
>
> Not so fast. I have hit the same issue and entirely agree. In
> general,
> the issue of making sure that an exception escapes when you want it to
> is a bit of a problem, and it would be nice to have some way of dealing
> with this, and not just with asserts. But certainly asserts should
> have
> the option for the kind of always-die behavior you're talking about.
let die_unless p s =
if not p then begin
Printf.printf "die: %s\n" s;
flush stdout;
exit (-1)
end
Slightly less convenient than assert, but has the effect of dying
immediately.
For my part, I *like* the behavior of assert and exception the way it
is.
--
j h woodyatt <jhw@wetware.com>
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-29 21:01 ` Chris Hecker
2003-07-30 10:22 ` Yaron M. Minsky
@ 2003-08-06 12:19 ` Michal Moskal
2003-08-06 14:50 ` William Lovas
1 sibling, 1 reply; 12+ messages in thread
From: Michal Moskal @ 2003-08-06 12:19 UTC (permalink / raw)
To: caml-list
On Tue, Jul 29, 2003 at 02:01:07PM -0700, Chris Hecker wrote:
> Another way of thinking about this is that almost everybody re-#defines
> assert in production C/C++ programs to do their own assert handling during
> development (whether it's printing out additional information, allowing you
> to drop into the debugger, popping up a message box, sending bug email,
> whatever). With assert hard-coded into ocaml, you can't do this.
try
main ()
with Assert_failure (line, col, file) -> (* or whatever it is *)
prerr_endline "Panic! Contact support"
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-08-06 12:19 ` Michal Moskal
@ 2003-08-06 14:50 ` William Lovas
2003-08-06 17:44 ` Michal Moskal
0 siblings, 1 reply; 12+ messages in thread
From: William Lovas @ 2003-08-06 14:50 UTC (permalink / raw)
To: caml-list
On Wed, Aug 06, 2003 at 02:19:41PM +0200, Michal Moskal wrote:
> On Tue, Jul 29, 2003 at 02:01:07PM -0700, Chris Hecker wrote:
> > Another way of thinking about this is that almost everybody re-#defines
> > assert in production C/C++ programs to do their own assert handling during
> > development (whether it's printing out additional information, allowing you
> > to drop into the debugger, popping up a message box, sending bug email,
> > whatever). With assert hard-coded into ocaml, you can't do this.
>
> try
> main ()
> with Assert_failure (line, col, file) -> (* or whatever it is *)
> prerr_endline "Panic! Contact support"
This won't trigger, though, if the exception has already been caught
upstream.
William
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-08-06 14:50 ` William Lovas
@ 2003-08-06 17:44 ` Michal Moskal
0 siblings, 0 replies; 12+ messages in thread
From: Michal Moskal @ 2003-08-06 17:44 UTC (permalink / raw)
To: caml-list
On Wed, Aug 06, 2003 at 10:50:21AM -0400, William Lovas wrote:
> On Wed, Aug 06, 2003 at 02:19:41PM +0200, Michal Moskal wrote:
> > On Tue, Jul 29, 2003 at 02:01:07PM -0700, Chris Hecker wrote:
> > > Another way of thinking about this is that almost everybody re-#defines
> > > assert in production C/C++ programs to do their own assert handling during
> > > development (whether it's printing out additional information, allowing you
> > > to drop into the debugger, popping up a message box, sending bug email,
> > > whatever). With assert hard-coded into ocaml, you can't do this.
> >
> > try
> > main ()
> > with Assert_failure (line, col, file) -> (* or whatever it is *)
> > prerr_endline "Panic! Contact support"
>
> This won't trigger, though, if the exception has already been caught
> upstream.
Of course, that's what's wrong with [try ... with _ -> ...]. What I
wanted to show is, that treating assert as an exception makes it
possible to customize it (with standard features of the language).
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] assert caught by try with _
2003-07-28 18:34 Chris Hecker
2003-07-28 19:08 ` Nicolas Cannasse
@ 2003-07-30 5:44 ` Jason Hickey
1 sibling, 0 replies; 12+ messages in thread
From: Jason Hickey @ 2003-07-30 5:44 UTC (permalink / raw)
Cc: caml-list
Chris Hecker wrote:
> Is the the "right thing" for assert to be caught by a try ... with _ ->
> ... block?
I don't know. It seems reasonable to have exceptional conditions caught
by the exception handler...
However, it may be reasonable to ask for more than one exception
type--it seems like poor software engineering to statically list *all*
the possible reasonable exceptions in a try/with block, except for
Assert_failure. This idea will fail as new exceptions are added.
To help avoid this problem, in our work we generally declare a type of
application errors (not the exact syntax but close enough):
type application_error =
NoClue
| BadIdea of string
| IWouldIfICouldButICantSoIWont
| ...
exception ApplicationError of application_error
All raises are of the form (raise (ApplicationError ...)), and the
"default" exception handler is (try ... with ApplicationError _ -> ...).
This idea works ok, but is not scalable.
Jason
--
Jason Hickey http://www.cs.caltech.edu/~jyh
Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257
-------------------
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
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2003-08-06 17:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-29 22:55 [Caml-list] assert caught by try with _ Martin Berger
-- strict thread matches above, loose matches on Subject: below --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox