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
[Caml-list] Catching exceptions into strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-11 (15:37)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Catching exceptions into strings
> That's really rather surprising.  Given that the manual recommends that
> users explicitly check for zero to avoid this exception

The manual suggests that instead of writing

        try x / y with Division_by_zero -> ...

you could also write

        if y = 0 then ... else x / y

and not only avoid the issue, but end up with clearer code as well.
However, this kind of transformation isn't always applicable.

> , why isn't the
> compiler simply inserting the check for them

This is a reasonable option -- much more reasonable than trying to
intercept the SIGFPE signal and somehow turn it into an exception.
I still have doubts that reporting division by zero via an exception
is really useful, though.

> where it happens to be necessary, and optimizing it out when it is not?

I'm more skeptical here.  I'm yet to see a practical compile-time
analysis that can prove that an integer expression is not zero in any
but the most trivial cases (the expression is a constant or a for-loop
index). (By "integer", I mean machine integers with modulo arithmetic.)

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