Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
A global exception handler...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jonathan Roewen  
View profile  
 More options Jul 6 2006, 10:44 am
Newsgroups: fa.caml
From: "Jonathan Roewen" <jonathan.roe...@gmail.com>
Date: Thu, 06 Jul 2006 14:44:37 UTC
Local: Thurs, Jul 6 2006 10:44 am
Subject: [Caml-list] A global exception handler...
Hi,

Is it possible to register a global exception handler?

I suppose I could just nest everything inside one giant function if I
really had to, but I like my toplevel expressions ;-)

Jonathan

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Till Varoquaux  
View profile  
 More options Jul 6 2006, 10:56 am
Newsgroups: fa.caml
From: "Till Varoquaux" <till.varoqu...@gmail.com>
Date: Thu, 06 Jul 2006 14:56:51 UTC
Local: Thurs, Jul 6 2006 10:56 am
Subject: Re: [Caml-list] A global exception handler...
On 7/6/06, Jonathan Roewen <jonathan.roe...@gmail.com> wrote:
> Hi,

> Is it possible to register a global exception handler?

> I suppose I could just nest everything inside one giant function if I
> really had to, but I like my toplevel expressions ;-)

CamlP4 might come in handy here. I'm guessing you could rewrite your
program so that all your toplevel expressions are in one main ()
function using camlp4. It would have some limitations though: for
instance your exception handler could not use anything defined in main
(unless you where using references). I'm guessing it's not so bad
because whatever happens you cannot have a global exception handler
relying to much on stuff defined in your programm.

> Jonathan

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicolas Pouillard  
View profile  
 More options Jul 6 2006, 11:30 am
Newsgroups: fa.caml
From: "Nicolas Pouillard" <nicolas.pouill...@inria.fr>
Date: Thu, 06 Jul 2006 15:30:52 UTC
Local: Thurs, Jul 6 2006 11:30 am
Subject: Re: [Caml-list] A global exception handler...
On 7/6/06, Till Varoquaux <till.varoqu...@gmail.com> wrote:

> On 7/6/06, Jonathan Roewen <jonathan.roe...@gmail.com> wrote:
> > Hi,

> > Is it possible to register a global exception handler?

> > I suppose I could just nest everything inside one giant function if I
> > really had to, but I like my toplevel expressions ;-)

> CamlP4 might come in handy here. I'm guessing you could rewrite your
> program so that all your toplevel expressions are in one main ()
> function using camlp4. It would have some limitations though: for
> instance your exception handler could not use anything defined in main
> (unless you where using references). I'm guessing it's not so bad
> because whatever happens you cannot have a global exception handler
> relying to much on stuff defined in your programm.

Here is a simple Camlp4 filter that written for the new Camlp4 version (CVS) :

$ cat global_handler.ml
open Camlp4.PreCast;

value ghost = Loc.ghost;

value global_handler_ref = ref <:expr@ghost<>>;

value find_global_handler = object
  inherit Ast.map as super;
  method str_item st = do {
    match st with
    [ <:str_item< value global_handler = $f$ >> -> global_handler_ref.val := f
    | _ -> () ];
    super#str_item st
  };
end;

AstFilters.register_str_item_filter
  (fun st ->
    let _ = find_global_handler#str_item st in
    <:str_item@ghost< try let module Main = struct $st$ end in ()
                      with e -> $global_handler_ref.val$ e >>);

$ ocamlc -I +camlp4 -c -pp camlp4rf global_handler.ml

$ cat global_handler_test.ml
open Format;;
let f1 x = printf "f1 %d@." x;;
let f2 x = printf "f2 %f@." x;;
let f3 x = printf "f3 %s@." x;;
f1 1;;
f2 1.1;;
f3 "1.1.1";;
raise (Failure "test");;
let global_handler e =
  (* Note that I need to give the complete name for eprintf since
     Format is not opened in the new environment of global_handler. *)
  Format.eprintf "global_handler: %s@." (Printexc.to_string e)

$ ocamlc -pp 'camlp4o global_handler.cmo' global_handler_test.ml

$ ./a.out
f1 1
f2 1.100000
f3 1.1.1
global_handler: Failure("test")

$ camlp4o global_handler.cmo -printer OCaml global_handler_test.ml
try
  let module Main =
    struct
      open Format
      let f1 x = printf "f1 %d@." x
      let f2 x = printf "f2 %f@." x
      let f3 x = printf "f3 %s@." x
      let _ = f1 1
      let _ = f2 1.1
      let _ = f3 "1.1.1"
      let _ = raise (Failure "test")
      let global_handler e =
        (* Note that I need to give the complete name for eprintf since
     Format is not opened in the new environment of global_handler. *)
        Format.eprintf "global_handler: %s@." (Printexc.to_string e)
    end
  in ()
with
| e ->
    (fun e -> Format.eprintf "global_handler: %s@." (Printexc.to_string e)) e

Cheers,

--
Nicolas Pouillard

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Roewen  
View profile  
 More options Jul 6 2006, 11:40 am
Newsgroups: fa.caml
From: "Jonathan Roewen" <jonathan.roe...@gmail.com>
Date: Thu, 06 Jul 2006 15:40:35 UTC
Local: Thurs, Jul 6 2006 11:40 am
Subject: Re: [Caml-list] A global exception handler...

Ah, defining a module inside a function is a neat trick! I didn't
think of that. Well, I guess it couldn't hurt to do that with all the
modules which could cause trouble at runtime...

Can I build the new camlp4 with 3.09.2 tools?

Jonathan

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicolas Pouillard  
View profile  
 More options Jul 6 2006, 11:41 am
Newsgroups: fa.caml
From: "Nicolas Pouillard" <nicolas.pouill...@gmail.com>
Date: Thu, 06 Jul 2006 15:41:21 UTC
Local: Thurs, Jul 6 2006 11:41 am
Subject: Re: [Caml-list] A global exception handler...
On 7/6/06, Jonathan Roewen <jonathan.roe...@gmail.com> wrote:

In fact camlp4 will be part of OCaml 3.10 distribution, so it's better
to try it directly like that, instead of mixing them with 3.09.2.

--
Nicolas Pouillard

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google