Browse thread
[Caml-list] Catching exceptions into strings
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Xavier Leroy <xleroy@p...> |
| Subject: | Re: [Caml-list] Catching exceptions into strings |
> I want to catch exceptions into strings. I do not want to have
> pre-defined exceptions in my module which can be handled. I want to
> catch exceptions like "floating point exceptions" etc.
>
> I wrote the follwing piece of code:
>
> value divide2 p = 2/p ;
>
> value foo p =
> try divide2 p
> with
> [e -> let _ = do {print_string (Printexc.to_string e);flush stdout} in 9];
>
> value _ = foo 0;
>
> (This code is in the Camlp4 revised syntax).
>
> When I compile and run this code, I get :
>
> Floating point exception
>
> However, after loading OCAML, if I use this file, I get
>
> value divide2 : int -> int = <fun>
> value arbit : int -> int = <fun>
> Division_by_zero
>
> That is, in the latter case, I get what I want but in the former
> case, I don't.
ocamlopt-generated code does not turn division by zero into an exception,
like ocamlc-generated code or the toplevel environment do. Instead,
you just get a hardware signal that kills the ocamlopt-generated program.
See section 11.4 of the OCaml manual for a complete list of
differences between ocamlopt and ocamlc.
- 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