<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/01/ff00f860be700a943d78413e07a43f74"
  from="Luc Maranget &lt;luc.maranget@i...&gt;"
  author="Luc Maranget"
  date="2003-01-21T13:55:52"
  subject="Re: [Caml-list] String of &apos;_&apos; (any) exception?"
  prev="2003/01/3e8e2b27f149125d2bc79f8f81f7238e"
  next="2003/01/bf6d813c0d03ff819c067945cbcbcabd"
  prev-thread="2003/01/b4a8ce11a48f9cc6cbf897c6b7a41e47"
  next-thread="2003/01/0e9c2bc35f3c3fbbe7e967dccafbddfc"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Re: [Caml-list] String of &apos;_&apos; (any) exception?">
<msg 
  url="2003/01/ff00f860be700a943d78413e07a43f74"
  from="Luc Maranget &lt;luc.maranget@i...&gt;"
  author="Luc Maranget"
  date="2003-01-21T13:55:52"
  subject="Re: [Caml-list] String of &apos;_&apos; (any) exception?">
</msg>
</thread>

<contents>
&gt; 
&gt; Hello,
&gt; 
&gt; does it exist a way to get hold of a the string (if any) associated
&gt; with an exception, when the exception has been caught with the "_"
&gt; (any) exception?  What I am interested in is to get hold of the
&gt; information which the run-time normally prints when it exits.
&gt; 
&gt; let _ = List.nth [4; 5] 4
&gt; 
&gt; itherther [14] [08:30] [~] ./a.out 
&gt; Fatal error: exception Failure("nth")
&gt; 
&gt; I want to get the string produced, or the information needed to
&gt; produce it myself.
&gt; 
&gt; The intended usage for this is in a RPC server library, where the
&gt; application raise some exception.  It would be convenient to re-raise
&gt; this as an remote exception, or at least report it back to the client.
&gt; 
&gt; 
&gt; Kindest regards,

Hello,

Have a look at the Printexc module
&lt;http://caml.inria.fr/ocaml/htmlman/libref/Printexc.html&gt;

As far as I understand your needs, you can write

try
  ...
with e -&gt;
  Printf.printf "Exception: %s\n" (Printexc.to_string e) ;
  raise e

Notice that the &lt;&lt; _ &gt;&gt; pattern is changed into a (binding) variable.


Cheers,

&gt; 
&gt; Hans Ole Rafaelsen
&gt; -------------------

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

</contents>

</message>

