Date: Thu, 18 Sep 2003 19:21:03 +0100 To: Jacques Garrigue Cc: lablgtk at kaba.or.jp Subject: Exception handling bug in GMain.Main (was: Re: Trapping exceptions at the top level? (repost)) Message-ID: <20030918182103.GA26041 at redhat.com> References: <20030912101328J.garrigue at kurims.kyoto-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030912101328J.garrigue at kurims.kyoto-u.ac.jp> From: Richard Jones On Fri, Sep 12, 2003 at 10:13:28AM +0900, Jacques Garrigue wrote: > [This mail was sent by Richard Jones ] > let rec run_main () = > try > GMain.Main.main () > with > Sys_error (...) -> > (* Some code to post a message_box describing this error. *); > run_main () I actually tried to implement this, but I've hit a Gtk/lablgtk bug. Attached is the minimal example I made to reproduce the bug. If you compile and run this program, then do: Click "Launch dialog" Click "OK" You get "You probably found a bug in this software ..." Click "OK" Click "X" (close) on the dialog window. Crash: GLib-GObject-ERROR **: file gsignal.c: line 646 (emission_pop): should not be reached aborting... Aborted It looks like GMain.Main.main can't safely have exceptions passing through it. This is with the CVS version 20030828. Rich. ---------------------------------------------------------------------- (* Exceptions and GMain.Main handling. * $Id: mainexn.ml,v 1.1 2003/09/18 18:16:47 rich Exp $ * To compile: * ocamlc -w s unix.cma -I +lablgtk2 lablgtk.cma gtkInit.cmo mainexn.ml \ * -o mainexn *) open Unix let rec run_main () = let display_error title msg = let icon = GMisc.image () in icon#set_stock `DIALOG_ERROR; icon#set_icon_size `DIALOG; GToolbox.message_box ~title ~icon msg in try GMain.Main.main () with Unix_error (err, syscall, filename) -> display_error "Filesystem error" (syscall ^ ": " ^ filename ^ ": " ^ error_message err); run_main () | Sys_error err -> display_error "System error" err; run_main () | Failure err -> display_error "Internal error" ("You probably found a bug in this software:\n\n" ^ err); run_main () let () = let window = GWindow.window () in window#connect#destroy ~callback:GMain.Main.quit; let button = GButton.button ~label:"Launch dialog" ~packing:window#add () in let callback () = let dialog = GWindow.dialog ~modal:true () in dialog#connect#destroy ~callback:GMain.Main.quit; let button = GButton.button ~label:"OK" ~packing:dialog#action_area#add () in button#connect#clicked ~callback:(fun () -> (* Simulate a failure in the normal processing of the * dialog. *) failwith "your foo is barred"); dialog#show (); run_main () in button#connect#clicked ~callback; window#show (); run_main () ---------------------------------------------------------------------- -- Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you. MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles, RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/