English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
RE: [Caml-list] Checked exceptions and type inference
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-03-12 (03:43)
From: mgushee@h...
Subject: RE: [Caml-list] Checked exceptions and type inference
On 11 Mar 2003 at 22:00, Arturo Borquez wrote:

> Brian Hurt <brian.hurt@qlogic.com> wrote:

> >Java treats checked exceptions as part of the type signature of the
> >function.  As such, it seems to me that as such, type inference would work
> >to propogate most of this information in a more convient way.

>  let x = try String.sub str pos len with _ -> "" in
>  ....
> in this case failing String.sub is returning a string,
> and the type inference system will check it that way.
> Perhaps I don't understand what migth be a
> 'checked exception' in ML. I am missing something?.
> can you explain it with an example?

I guess you must be unfamiliar with Java terminology. A checked 
exception is one that the programmer must provide for in any method 
that can raise it, either by writing a handler or by indicating in 
the method signature that the method may raise that exception. 
They're called "checked" because the compiler checks whether they are 
handled. For example, if you have a method getConfig() that reads a 
configuration file, you have to provide for possible I/O errors: 

    try {
        /* open and read file */
    } catch (IOException e) {
        /* handle exception */

Within the body of the method, or a signature such as:

    public HashTable getConfig() throws IOException {
        /* do whatever */

so in the latter case, the exception is indeed part of the method 

Unchecked exceptions are generally those resulting from unpredictable 
conditions, such as OutOfMemoryError, NullPointerException, and 

Matt Gushee
Englewood, CO USA

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