caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] exception handling questions
@ 2003-11-06  8:38 Dustin Sallings
  2003-11-06  9:02 ` Richard Jones
  2003-11-06  9:47 ` Oleg Trott
  0 siblings, 2 replies; 8+ messages in thread
From: Dustin Sallings @ 2003-11-06  8:38 UTC (permalink / raw)
  To: Caml Mailing List


	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.

-- 
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2003-11-06  8:38 [Caml-list] exception handling questions Dustin Sallings
@ 2003-11-06  9:02 ` Richard Jones
  2003-11-06  9:50   ` Dustin Sallings
  2003-11-06  9:47 ` Oleg Trott
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Jones @ 2003-11-06  9:02 UTC (permalink / raw)
  Cc: Caml Mailing List

On Thu, Nov 06, 2003 at 12:38:27AM -0800, Dustin Sallings 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.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
"I wish more software used text based configuration files!"
 -- A Windows NT user, quoted on Slashdot.

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2003-11-06  8:38 [Caml-list] exception handling questions Dustin Sallings
  2003-11-06  9:02 ` Richard Jones
@ 2003-11-06  9:47 ` Oleg Trott
  2003-11-06 10:39   ` Dustin Sallings
  1 sibling, 1 reply; 8+ messages in thread
From: Oleg Trott @ 2003-11-06  9:47 UTC (permalink / raw)
  To: Dustin Sallings, Caml Mailing List

On Thursday 06 November 2003 03:38 am, Dustin Sallings wrote:
>         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.

Printexc.to_string : exn -> string

-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2003-11-06  9:02 ` Richard Jones
@ 2003-11-06  9:50   ` Dustin Sallings
  2003-11-06  9:56     ` Richard Jones
  2004-01-31  1:02     ` Eric Stokes
  0 siblings, 2 replies; 8+ messages in thread
From: Dustin Sallings @ 2003-11-06  9:50 UTC (permalink / raw)
  To: Richard Jones; +Cc: Caml Mailing List


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
;;

	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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2003-11-06  9:50   ` Dustin Sallings
@ 2003-11-06  9:56     ` Richard Jones
  2004-01-31  1:02     ` Eric Stokes
  1 sibling, 0 replies; 8+ messages in thread
From: Richard Jones @ 2003-11-06  9:56 UTC (permalink / raw)
  To: caml-list

On Thu, Nov 06, 2003 at 01:50:30AM -0800, Dustin Sallings wrote:
> 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.

You might want to have a look at the code in lablgtk2 (the latest
released version). The user exception handler manages to print out
exceptions in full somehow. I'm not sure how it does it - perhaps it
uses a C function? Anyway, worth a look.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MONOLITH is an advanced framework for writing web applications in C, easier
than using Perl & Java, much faster and smaller, reusable widget-based arch,
database-backed, discussion, chat, calendaring:
http://www.annexia.org/freeware/monolith/

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2003-11-06  9:47 ` Oleg Trott
@ 2003-11-06 10:39   ` Dustin Sallings
  0 siblings, 0 replies; 8+ messages in thread
From: Dustin Sallings @ 2003-11-06 10:39 UTC (permalink / raw)
  To: Oleg Trott; +Cc: Caml Mailing List


On Nov 6, 2003, at 1:47, Oleg Trott wrote:

> On Thursday 06 November 2003 03:38 am, Dustin Sallings wrote:
>>         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.
>
> Printexc.to_string : exn -> string

	Thanks, that's exactly what I was looking for, yet somehow unable to 
see even though it's right there in the docs.

-- 
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2003-11-06  9:50   ` Dustin Sallings
  2003-11-06  9:56     ` Richard Jones
@ 2004-01-31  1:02     ` Eric Stokes
  2004-01-31  1:50       ` Dustin Sallings
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Stokes @ 2004-01-31  1:02 UTC (permalink / raw)
  To: Dustin Sallings; +Cc: Richard Jones, Caml Mailing List


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] exception handling questions
  2004-01-31  1:02     ` Eric Stokes
@ 2004-01-31  1:50       ` Dustin Sallings
  0 siblings, 0 replies; 8+ messages in thread
From: Dustin Sallings @ 2004-01-31  1:50 UTC (permalink / raw)
  To: Eric Stokes; +Cc: Caml List


On Jan 30, 2004, at 17:02, Eric Stokes wrote:

> 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.

	fn is a string, so feeding the same value back in wouldn't help.

	The real problem here was a runtime failure in one of the functions 
that is very unlikely to occur where this program is actually deployed. 
  I just wanted to make sure that when a failure did occur, it was dealt 
with properly.  The ``unknown error'' part was my biggest concern, 
because I really didn't have a way to know what went wrong.

	The answer to my main concern was the Printexc module:

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);
         print_endline (Printexc.to_string x);
         false

-- 
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-01-31  1:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-06  8:38 [Caml-list] exception handling questions Dustin Sallings
2003-11-06  9:02 ` Richard Jones
2003-11-06  9:50   ` Dustin Sallings
2003-11-06  9:56     ` Richard Jones
2004-01-31  1:02     ` Eric Stokes
2004-01-31  1:50       ` Dustin Sallings
2003-11-06  9:47 ` Oleg Trott
2003-11-06 10:39   ` Dustin Sallings

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).