caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Angela Zhu <angela.zhu@cs.rice.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] How to prevent program from crashing
Date: Wed, 31 Oct 2007 16:08:41 +1100	[thread overview]
Message-ID: <1193807321.8355.10.camel@rosella.wigram> (raw)
In-Reply-To: <F2E41546-0345-4E16-949C-C5515555C4FB@cs.rice.edu>


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


  reply	other threads:[~2007-10-31  5:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-31  4:29 Angela Zhu
2007-10-31  5:08 ` skaller [this message]
     [not found]   ` <ED53732F-0753-4F6C-B424-A24714CBC8F7@cs.rice.edu>
2007-10-31  6:54     ` Re:Re: [Caml-list] " skaller
2007-10-31  7:13       ` Angela Zhu
2007-10-31  7:47       ` Jacques Garrigue
2007-10-31  9:31         ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1193807321.8355.10.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=angela.zhu@cs.rice.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).