134
120
<p>Being "home-grown" make our exception mecanic both stronger and weaker at the same time. First it is weaker because, well, we are more limitated within the library as we are than if we could change the compiler itself to add some extra checks here and specific treatment there. But it is also a advantage for us, since the exception mecanism is perfectly fitted to the distributed settings of GRAS processes. They can easily propagate on the net, as we will see in the next lesson (<a class="el" href="GRAS_tut_tour_rpc.html">Lesson 10: Remote Procedure Calling (RPC)</a>) and contain information about the host on which they were thrown (<a class="el" href="structxbt__ex__t.html" title="Structure describing an exception.">xbt_ex_t</a>) along with the thrown point in the source code.</p>
135
121
<p>The syntax of XBT exceptions should not sound unfamilliar to most of you. You throw them using the <a class="el" href="group__XBT__ex.html#gae18641b6be3a88a74eb003978399fe90" title="Builds and throws an exception.">THROW</a> and <a class="el" href="group__XBT__ex.html#gaf104c05a68884bf85630ef40ca8ae774" title="Builds and throws an exception with a printf-like formatted message.">THROWF</a> macros. They take 2 arguments: an error category (of type <a class="el" href="group__XBT__ex.html#gaa45fec59aa57056784554a7f998f0854" title="different kind of errors">xbt_errcat_t</a>) and an error "value" (an integer; pratically, this is often left to 0 in my own code). <a class="el" href="group__XBT__ex.html#gaf104c05a68884bf85630ef40ca8ae774" title="Builds and throws an exception with a printf-like formatted message.">THROWF</a> also takes a message string as extra argument which is a printf-like format string with its own arguments. So, you may have something like the following: </p>
136
122
<div class="fragment"><pre class="fragment">THROWF(system_error, 0, "Cannot connect to %s:%d because of %s", hostname, port, reason);</pre></div><p>Then, you simply add a <a class="el" href="group__XBT__ex.html#gad2746371528bdf15c3910b7bf217dac0" title="Introduce a block where exception may be dealed with.">TRY</a>/<a class="el" href="group__XBT__ex.html#gab3271e393133e395129cc74272f9fae2" title="the block for catching (ie, deal with) an exception">CATCH</a> block around your code: </p>
141
127
/* error handling code */