From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA19111 for caml-redistribution; Tue, 26 Jan 1999 18:44:24 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA00350 for ; Tue, 26 Jan 1999 01:24:38 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id BAA08913; Tue, 26 Jan 1999 01:24:35 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA08111; Tue, 26 Jan 1999 01:24:35 +0100 (MET) Message-ID: <19990126012435.21454@pauillac.inria.fr> Date: Tue, 26 Jan 1999 01:24:35 +0100 From: Xavier Leroy To: Ian T Zimmerman , caml-list@inria.fr Subject: Re: Catching Break? References: <199901251843.KAA23637@kronstadt.transbay.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <199901251843.KAA23637@kronstadt.transbay.net>; from Ian T Zimmerman on Mon, Jan 25, 1999 at 10:43:01AM -0800 Sender: weis > Why doesn't this work: > > let main() = > Sys.catch_break true; > try Unix.kill (Unix.getpid()) Sys.sigint > with Sys.Break -> prerr_endline "CAUGHT!"; exit 0 > > let _ = main() > > This program just prints "Fatal error: Uncaught exception Sys.Break" > as if the try block weren't there. Am I overlooking something really > obvious? No, it's fairly subtle, actually. For various reasons related to the Caml runtime system, signals in OCaml are not necessarily handled at the program point where they are received: the signal handler is called only at the next "safe" program point. In the case of the ocamlc bytecode interpreter, "safe" program points are at function application and at the beginning of each loop iteration. So, in your example above, we leave the "try..with" before the handler for the signal is called, and that handler thus raises the Sys.Break exception outside of the "try..with". If you add a function call after the Unix.kill, everything should work as expected: > let main() = > Sys.catch_break true; > try Unix.kill (Unix.getpid()) Sys.sigint; prerr_endline "Sent signal" > with Sys.Break -> prerr_endline "CAUGHT!"; exit 0 This is actually a minor OCaml bug; it would be better to check for pending signals just before leaving a "try..with" block. I'll see what can be done about it. - Xavier Leroy