From: William Chesters <williamc@paneris.org>
To: caml-list@inria.fr
Subject: [Caml-list] Checked exceptions and type inference
Date: 12 Mar 2003 18:45:58 -0000 [thread overview]
Message-ID: <20030312184558.14942.qmail@www.paneris.org> (raw)
In-Reply-To: <Pine.LNX.4.33.0303111538120.2164-100000@eagle.ancor.com>
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
next prev parent reply other threads:[~2003-03-12 18:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-11 21:50 Brian Hurt
2003-03-12 5:40 ` Jacques Garrigue
2003-03-12 8:45 ` Xavier Leroy
2003-03-12 10:12 ` Stefano Zacchiroli
2003-03-12 16:34 ` Xavier Leroy
2003-03-12 17:20 ` Richard W.M. Jones
2003-03-12 20:49 ` Brian Hurt
2003-03-12 18:45 ` William Chesters [this message]
2003-03-12 3:00 Arturo Borquez
2003-03-12 3:24 ` Nicolas Cannasse
2003-03-12 3:43 ` mgushee
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=20030312184558.14942.qmail@www.paneris.org \
--to=williamc@paneris.org \
--cc=caml-list@inria.fr \
/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