* How to prevent program from crashing @ 2007-10-31 4:29 Angela Zhu 2007-10-31 5:08 ` [Caml-list] " skaller 0 siblings, 1 reply; 6+ messages in thread From: Angela Zhu @ 2007-10-31 4:29 UTC (permalink / raw) To: caml-list [-- Attachment #1: Type: text/plain, Size: 685 bytes --] Dear all, I am trying to develop a new language with GUI using OCaml. However, the language seems to be not very stable. If a small syntax error in the program(written in this new language) happens, it can through an error message. If the syntax error is kind of critical, (e.g., a semi-colon is missed at the end of a line, or a keyword is mis-spelled) Then the whole GUI of the language crashes. Does anyone else have ever encountered similar problem? Or can anyone give me a hint on how to prevent this? Thanks a lot! Angela ------------------------------------------ Dept. of CS, Rice Unitersity http://www.cs.rice.edu/~yz2/ ------------------------------------------ [-- Attachment #2: Type: text/html, Size: 1753 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] How to prevent program from crashing 2007-10-31 4:29 How to prevent program from crashing Angela Zhu @ 2007-10-31 5:08 ` skaller [not found] ` <ED53732F-0753-4F6C-B424-A24714CBC8F7@cs.rice.edu> 0 siblings, 1 reply; 6+ messages in thread From: skaller @ 2007-10-31 5:08 UTC (permalink / raw) To: Angela Zhu; +Cc: caml-list On Tue, 2007-10-30 at 23:29 -0500, Angela Zhu wrote: > > If a small syntax error in the program(written in this new language) > happens, [] > Then the whole GUI of the language crashes. You need to isolate the GUI part of your program from the part that handles errors. In particular you should be careful to undo the unfortunate tendency of various Ocaml functions to throw exceptions, and thereby 'crash' your program if you fail to handle them. For example write: let hfind msg table key = try Hashtbl.find table key with Not_found -> print_endline ("Hashtbl.find failed in " ^ msg); abort() ;; let maybe_hfind table key = try Some (Hashtbl.find table key) with Not_found -> None ;; and use one or other of these functions instead of the raw Hashtbl.find function, which can throw an exception you forget to catch and crash your program without a clear reason. Here 'hfind' will still crash your program, but hopefully help find your programming error, whereas the maybe_hfind function will never fail and uses the type system to force you to check for errors and handle them. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <ED53732F-0753-4F6C-B424-A24714CBC8F7@cs.rice.edu>]
* Re: Re:Re: [Caml-list] How to prevent program from crashing [not found] ` <ED53732F-0753-4F6C-B424-A24714CBC8F7@cs.rice.edu> @ 2007-10-31 6:54 ` skaller 2007-10-31 7:13 ` Angela Zhu 2007-10-31 7:47 ` Jacques Garrigue 0 siblings, 2 replies; 6+ messages in thread From: skaller @ 2007-10-31 6:54 UTC (permalink / raw) To: Angela Zhu; +Cc: caml On Wed, 2007-10-31 at 00:52 -0500, Angela Zhu wrote: > And I am sure the whole program and GUI crashes when function > "resetState2_4openFile" > is called. > I tried to catch the exception, but seems that it doesn't work. > > Following is the message I got after the crashing: > > > ************************************************************************ > ************************ > (acumen:4063): Gtk-CRITICAL **: _gtk_text_line_char_locate: assertion > `char_offs > et >= 0' failed > > Gtk-ERROR **: Char offset -1 is off the end of the line > aborting... > Abort trap Yeah, this is an abort from a failed assertion in C, so it isn't an Ocaml exception. I don't know how GTK handles this, that is, whether there is a way to register an error handler. You should ask Jacques Garrigue that.. hmmm. no I'll post this to the list because this is quite an interesting issue. It would appear that this line in your code, which calls the GTK binding: let appp = program2#buffer#get_text() is the source of the problem, and that would be a bug in the Ocaml library, not your code. Even if the buffer is empty, at least Ocaml the library should handle this. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Re: Re:Re: [Caml-list] How to prevent program from crashing 2007-10-31 6:54 ` skaller @ 2007-10-31 7:13 ` Angela Zhu 2007-10-31 7:47 ` Jacques Garrigue 1 sibling, 0 replies; 6+ messages in thread From: Angela Zhu @ 2007-10-31 7:13 UTC (permalink / raw) To: skaller; +Cc: caml-list > > Yeah, this is an abort from a failed assertion in C, > so it isn't an Ocaml exception. > > I don't know how GTK handles this, that is, whether there is > a way to register an error handler. You should ask > Jacques Garrigue that.. hmmm. no I'll post this to the list > because this is quite an interesting issue. > Thank you very much for your attention. I wish this can be solved any way. :( Best regards, Angela ------------------------------------------ Dept. of CS, Rice Unitersity http://www.cs.rice.edu/~yz2/ ------------------------------------------ > > It would appear that this line in your code, which calls the > GTK binding: > > let appp = program2#buffer#get_text() > > is the source of the problem, and that would be a bug in the Ocaml > library, not your code. Even if the buffer is empty, at least Ocaml > the library should handle this. > > > -- > John Skaller <skaller at users dot sf dot net> > Felix, successor to C++: http://felix.sf.net > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] How to prevent program from crashing 2007-10-31 6:54 ` skaller 2007-10-31 7:13 ` Angela Zhu @ 2007-10-31 7:47 ` Jacques Garrigue 2007-10-31 9:31 ` skaller 1 sibling, 1 reply; 6+ messages in thread From: Jacques Garrigue @ 2007-10-31 7:47 UTC (permalink / raw) To: skaller; +Cc: angela.zhu, caml-list From: skaller <skaller@users.sourceforge.net> > > Following is the message I got after the crashing: > > > > > > ************************************************************************ > > ************************ > > (acumen:4063): Gtk-CRITICAL **: _gtk_text_line_char_locate: assertion > > `char_offs > > et >= 0' failed > > > > Gtk-ERROR **: Char offset -1 is off the end of the line > > aborting... > > Abort trap > > Yeah, this is an abort from a failed assertion in C, > so it isn't an Ocaml exception. > > I don't know how GTK handles this, that is, whether there is > a way to register an error handler. You should ask > Jacques Garrigue that.. hmmm. no I'll post this to the list > because this is quite an interesting issue. > > It would appear that this line in your code, which calls the > GTK binding: > > let appp = program2#buffer#get_text() > > is the source of the problem, and that would be a bug in the Ocaml > library, not your code. Even if the buffer is empty, at least Ocaml > the library should handle this. If this is intended as a bug report, this is a poor one indeed. We need at least the version numbers for both Gtk and LablGTK2, and the actual code... As it is, buffer#get_text () seems to work perfectly with empty buffers, with the latest version of LablGTK2, and Gtk-2.6.10. Independently of that, text iterators can be very tricky to use manually. LablGTK attempts at catching errors, but Gtk sometimes crashes after the exception is caught... So better to be sure to make no error. Jacques Garrigue ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] How to prevent program from crashing 2007-10-31 7:47 ` Jacques Garrigue @ 2007-10-31 9:31 ` skaller 0 siblings, 0 replies; 6+ messages in thread From: skaller @ 2007-10-31 9:31 UTC (permalink / raw) To: Jacques Garrigue; +Cc: caml-list On Wed, 2007-10-31 at 16:47 +0900, Jacques Garrigue wrote: > From: skaller <skaller@users.sourceforge.net> > > It would appear that this line in your code, which calls the > > GTK binding: > > > > let appp = program2#buffer#get_text() > If this is intended as a bug report, this is a poor one indeed. No, it isn't a bug report! It's a general request for more information, maybe some help figuring out how this could happen? Could you cause this with Ocaml code? -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-10-31 9:31 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-10-31 4:29 How to prevent program from crashing Angela Zhu 2007-10-31 5:08 ` [Caml-list] " skaller [not found] ` <ED53732F-0753-4F6C-B424-A24714CBC8F7@cs.rice.edu> 2007-10-31 6:54 ` skaller 2007-10-31 7:13 ` Angela Zhu 2007-10-31 7:47 ` Jacques Garrigue 2007-10-31 9:31 ` skaller
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox