caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benjamin Geer <ben@socialtools.net>
To: Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] GC and file descriptors
Date: Tue, 18 Nov 2003 18:26:33 +0000	[thread overview]
Message-ID: <3FBA6459.3000000@socialtools.net> (raw)
In-Reply-To: <3FBA4D97.9060309@dcs.qmul.ac.uk>

Martin Berger wrote:
>> What alternatives are there?
>> One is to  have exception specifications on functions,
>> but that is known not to work very well. [...]
> 
> but isn't this snowballing exactly what you want?

I think it is.  It's very reassuring to know that the compiler can tell 
me whether I've left any exceptions unhandled, just as it can tell me 
whether I've neglected to provide a suitable return value for a function.

 From experience working on fairly large programs in Java, I can say (at 
the risk of being pelted with stones on this list) that I think the way 
Java handles this works pretty well.  You can avoid having any methods 
specify more than two or three exceptions by using hierarchies of 
exception subtypes (e.g. IOException has subtypes FileNotFoundException, 
SocketException and so on) and by using nested exception objects (e.g. a 
FooSubsystemException can contain an instance of any other exception, 
and can thus be handled by a method that only specifies 
FooSubsystemException).  Nested exceptions have the useful property that 
when you get a stack trace from an exception (e.g. in order to log it), 
it recursively includes the stack traces of any nested exceptions.

In Caml, as in C++, I'm left with a lingering anxiety about what 
exceptions might be thrown (particularly by libraries, including the 
standard libraries) but not handled except by a catch-all 'unhandled 
exception handler', at which point it's too late to do anything useful 
with them.  (And Caml exceptions lack stack traces.)

Annoying problems arise in Java with unchecked exceptions; things like 
IndexOutOfBoundsException (which can be thrown by any array access) or 
ArithmeticException (e.g. division by zero) don't have to be declared in 
exception specifications, and therefore never are.  Bugs often result in 
programs crashing with an unhandled NullPointerException (which of 
course can't happen in Caml).  Ideally, the number of possible unchecked 
exceptions should be kept to an absolute minimum; I think there are too 
many in Java.

I wish I knew what the ideal solution was, but I think Caml could do 
worse than to implement a Java-like approach.  It seems to me that this 
would be more consistent with Caml's overall focus on type safety than 
its current C++-like approach.

 > i always wonder if problem would simply disappear with more
 > expressive typing systems that allow concise specification
 > of the normal case for exceptions -- where an piece of code is
 > just a conduit for exceptions -- and appropriate grouping of
 > exceptions, for example by subtyping.

If the type of a function included its exception specification, could 
Caml infer exception specifications?  If so, perhaps exception 
specifications could be added to the language without breaking backwards 
compatibility.  If I wrote this:

let divide x y = x / y ;;
let do_work x y = divide x y ;;

the type of both functions would be inferred as having an exception 
specification containing Division_by_zero.  Now suppose I wrote the 
following (meaning that the function do_work explicitly specifies the 
exception Sys_error):

let do_work x [ Sys_error ] = let z = (* ... *) in divide x z ;;

I would get a compile error, because I should have written:

let do_work x [ Sys_error; Division_by_zero ] = let z = (* ... *) in 
divide x z ;;

When using libraries that were written before the introduction of 
exception specifications, I could verify that all library exceptions 
were handled, by calling a library function in the following way:

let do_work x [] = (* Call some library functions that don't have 
explicit exception specifications *) ;;

The compiler would then tell me which exceptions I'd failed to handle.

Does this seem feasible?

Ben

-------------------
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


  parent reply	other threads:[~2003-11-18 18:26 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-13  0:50 Dustin Sallings
2003-11-13  1:18 ` David Fox
2003-11-13  4:09   ` Dustin Sallings
2003-11-14 13:42     ` Damien Doligez
2003-11-14 14:57       ` Christophe Raffalli
2003-11-14 20:24         ` Dmitry Bely
2003-11-14 20:54           ` Eric Dahlman
2003-11-14 22:21             ` Brian Hurt
2003-11-14 21:36               ` John J Lee
2003-11-14 21:48           ` Brian Hurt
2003-11-15  1:47             ` Dmitry Bely
2003-11-15  2:25           ` Max Kirillov
2003-11-15  2:49             ` Mike Furr
2003-11-16  4:09               ` [Caml-list] Bugs from ignoring errors from close (was Re: GC and file..) Tim Freeman
2003-11-15  2:58             ` [Caml-list] GC and file descriptors David Brown
2003-11-17 14:19         ` Damien Doligez
2003-11-17 18:18           ` skaller
2003-11-14 18:35       ` Dustin Sallings
2003-11-15 14:16         ` skaller
2003-11-15 15:56           ` Ville-Pertti Keinonen
2003-11-15 17:30             ` skaller
2003-11-15 20:31               ` Martin Berger
2003-11-16 19:19               ` Brian Hurt
2003-11-17 18:15                 ` skaller
2003-11-17 19:26                   ` Aleksey Nogin
2003-11-18 13:49                     ` skaller
2003-11-18 17:51                       ` Dustin Sallings
2003-11-18 20:17                       ` Aleksey Nogin
2003-11-20  7:36                         ` Florian Hars
2003-11-17 21:20                   ` Brian Hurt
2003-11-17 23:02                     ` John J Lee
2003-11-18 12:05                     ` Ville-Pertti Keinonen
2003-11-18 15:19                       ` skaller
2003-11-18 18:10                         ` John J Lee
2003-11-18 17:55                           ` skaller
2003-11-18 20:02                         ` Ville-Pertti Keinonen
2003-11-18 21:20                           ` John J Lee
2003-11-19 12:25                           ` skaller
2003-11-19 13:55                             ` Ville-Pertti Keinonen
2003-11-19 14:26                               ` Samuel Lacas
2003-11-19 14:47                               ` skaller
2003-11-18 15:28                       ` skaller
2003-11-18 18:00                       ` John J Lee
2003-11-18 22:28                       ` Brian Hurt
2003-11-18 23:07                         ` John J Lee
2003-11-18 23:22                         ` Benjamin Geer
2003-11-19  1:49                         ` Martin Berger
2003-11-19  3:57                           ` Dustin Sallings
2003-11-19 13:35                           ` skaller
2003-11-19 13:00                         ` skaller
2003-11-19 13:02                         ` skaller
2003-11-19 17:36                           ` Brian Hurt
2003-11-20  5:14                             ` skaller
2003-11-20  7:37                               ` David Brown
2003-11-18 15:12                     ` skaller
2003-11-18 16:49                       ` Martin Berger
2003-11-18 17:46                         ` skaller
2003-11-19  1:33                           ` Martin Berger
2003-11-19  3:19                             ` Design by Contract, was " Brian Hurt
2003-11-19  2:57                               ` Jacques Carette
2003-11-19 13:27                             ` skaller
2003-11-19 14:41                               ` Martin Berger
2003-11-19 16:54                             ` Richard Jones
2003-11-19 17:18                               ` Damien Doligez
2003-11-19 21:45                                 ` Richard Jones
2003-11-19 23:09                                   ` Benjamin Geer
2003-11-20  0:50                                     ` Nicolas Cannasse
2003-11-20  9:42                                       ` Benjamin Geer
2003-11-19 18:03                               ` Martin Berger
2003-11-18 18:26                         ` Benjamin Geer [this message]
2003-11-18 19:24                           ` Xavier Leroy
2003-11-18 23:49                             ` Benjamin Geer
2003-11-19  1:36                             ` Martin Berger
2003-11-19  2:28                               ` Nicolas Cannasse
2003-11-19  3:26                               ` Brian Hurt
2003-11-19 11:44                                 ` Martin Berger
2003-11-19 17:29                                   ` Brian Hurt
2003-11-20  5:17                                     ` skaller
2003-11-20 16:13                                       ` Brian Hurt
2003-11-19 13:33                               ` skaller
2003-11-19 17:01                                 ` Richard Jones
2003-11-22  2:39                                   ` [Caml-list] AutoMLI (Was: GC and file descriptors) Jim
2003-11-19 17:43                                 ` [Caml-list] GC and file descriptors Brian Hurt
2003-11-20  5:05                                   ` skaller
2003-11-19  1:33                           ` Martin Berger
2003-11-19  2:47                             ` Benjamin Geer
2003-11-18 22:23                       ` Brian Hurt
2003-11-19 13:00                         ` skaller
2003-11-17 22:37                   ` OCaml popularity [was: Re: [Caml-list] GC and file...] John J Lee
2003-11-18  1:02                   ` [Caml-list] Re: GC and file descriptors Jed Davis
2003-11-13  1:19 ` [Caml-list] " Nicolas George
     [not found] ` <87smkstkhg.fsf@igloo.phubuh.org>
     [not found]   ` <347A7A46-1612-11D8-8F93-000393CFE6B8@spy.net>
2003-11-13 20:18     ` Mikael Brockman
     [not found] <20031118232227.GA8437@swordfish>
     [not found] ` <Pine.LNX.4.44.0311182039440.5009-100000@localhost.localdomain>
2003-11-20  6:35   ` Matt Gushee
2003-11-21 16:44     ` skaller
2003-11-21 22:17 Gregory Morrisett

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=3FBA6459.3000000@socialtools.net \
    --to=ben@socialtools.net \
    --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;
as well as URLs for NNTP newsgroup(s).