From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA31161; Sat, 31 Jan 2004 02:08:32 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA31011 for ; Sat, 31 Jan 2004 02:08:30 +0100 (MET) Received: from plover.csun.edu (plover.csun.edu [130.166.1.24]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0V14nv03755 for ; Sat, 31 Jan 2004 02:04:51 +0100 (MET) Received: from puffin.csun.edu (puffin.csun.edu [130.166.1.21]) by plover.csun.edu (MOS 3.4.4-GR) with ESMTP id AXF74726; Fri, 30 Jan 2004 17:02:53 -0800 (PST) Received: from [130.166.10.182] (s010n182.csun.edu [130.166.10.182]) by puffin.csun.edu (Mirapoint Messaging Server MOS 3.3.8-GR) with ESMTP id BHX55227 (AUTH eric); Fri, 30 Jan 2004 17:02:15 -0800 (PST) In-Reply-To: References: <979ADAF0-1034-11D8-ADB5-000393CFE6B8@spy.net> <20031106090201.GA9550@redhat.com> Mime-Version: 1.0 (Apple Message framework v612) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <1B178E7D-5389-11D8-B58E-000A95A1E69A@csun.edu> Content-Transfer-Encoding: 7bit Cc: Richard Jones , Caml Mailing List From: Eric Stokes Subject: Re: [Caml-list] exception handling questions Date: Fri, 30 Jan 2004 17:02:13 -0800 To: Dustin Sallings X-Mailer: Apple Mail (2.612) X-Junkmail-Whitelist: YES (by domain whitelist at puffin.csun.edu) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ocamlrun:01 endline:01 endline:01 passwd:01 passwd:01 abort:01 bug:01 faq:01 faq:01 beginner's:01 beginners:01 bin:01 caml-bugs:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Nov 6, 2003, at 1:50 AM, Dustin Sallings wrote: > > On Nov 6, 2003, at 1:02, Richard Jones wrote: > >>> One thing that really seems to be missing from exception handling is >>> the ability to print a stack trace from an exception. I realize >>> there's a flag on the ocamlrun to print stacks for uncaught >>> exceptions, >>> but that's not exactly what I'm looking for. I'd like to be able to >>> catch and exception, log it, and continue. >>> >>> Similarly, is there a way to print an exception at least like the >>> toplevel does? I can catch any type of exception with the >>> appropriate >>> pattern, but I don't see how I can report it without expecting it. >> >> And while we're at it, printing out a full stack trace with function >> names and parameters. > > Yes, that would be nice, but I'm trying to not ask for too much. :) > As it is, I've got a function that can fail when processing large > amounts of data and it's OK to lose one as long as I know why. Right > now, the only way to know why is to rethrow: > > let should_process fn = > try > (ends_with fn ".") && (is_new_enough fn) && (not (is_gzip fn)) > with x -> > print_endline("Unknown error determining whether to process " > ^ fn); > raise x > ;; > What about doing this. let rec should_process fn = try (ends_with fn ".") && (is_new_enough fn) && (not (is_gzip fn)) with x -> print_endline("Unknown error determining whether to process " ^ fn); should_process fn ;; You may need to maintain a bit more state in various places, but it could work the way you want. > Example output: > > Unknown error determining whether to process /tmp/x/passwd. > Fatal error: exception Sys_error("/tmp/x/passwd.: Permission denied") > > I'd be plenty happy to print out that message and continue, but in > the meantime, I've gotta have it abort. > > -- > Dustin Sallings > > ------------------- > 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 > ------------------- 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