~ubuntu-branches/ubuntu/quantal/simgrid/quantal

« back to all changes in this revision

Viewing changes to doc/html/GRAS_tut_tour_exceptions.html

  • Committer: Package Import Robot
  • Author(s): Lucas Nussbaum, Martin Quinson, Lucas Nussbaum
  • Date: 2012-06-09 16:24:44 UTC
  • mfrom: (10.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20120609162444-xook34f3d6qy5ixj
Tags: 3.7.1-1
[ Martin Quinson ]
* debian/copyright: update FSF address (thanks lintian for noticing)

[ Lucas Nussbaum ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
3
<head>
4
4
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5
 
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6
5
<title>SimGrid: Lesson 8: Handling errors through exceptions</title>
7
 
 
8
6
<link href="tabs.css" rel="stylesheet" type="text/css"/>
9
 
<link href="doxygen.css" rel="stylesheet" type="text/css" />
10
 
 
11
 
 
12
 
 
 
7
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
13
8
<link href="simgrid.css" rel="stylesheet" type="text/css">
14
9
</head>
15
10
<body>
16
 
<div id="top"><!-- do not remove this div! -->
17
 
 
18
 
 
 
11
<!-- Generated by Doxygen 1.7.4 -->
 
12
<div id="top">
19
13
<div id="titlearea">
20
14
<table cellspacing="0" cellpadding="0">
21
15
 <tbody>
22
16
 <tr style="height: 56px;">
23
 
  
24
 
  
25
17
  <td style="padding-left: 0.5em;">
26
 
   <div id="projectname">SimGrid
27
 
   &#160;<span id="projectnumber">3.7</span>
28
 
   </div>
 
18
   <div id="projectname">SimGrid&#160;<span id="projectnumber">3.7.1</span></div>
29
19
   <div id="projectbrief">Scalable simulation of distributed systems</div>
30
20
  </td>
31
 
  
32
 
  
33
 
  
34
21
 </tr>
35
22
 </tbody>
36
23
</table>
37
24
</div>
38
 
 
39
 
<!-- Generated by Doxygen 1.7.6.1 -->
40
25
  <div id="navrow1" class="tabs">
41
26
    <ul class="tablist">
42
27
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
65
50
  <li> <a href="group__API__index.html"><span>Full Index</span></a></li>
66
51
  <li> <a href="group__XBT__API.html"><span>XBT</span></a></li>
67
52
  <li> <a href="group__MSG__API.html"><span>MSG</span></a></li>
 
53
  <li> <a href="group__SIMIX__API.html"><span>SIMIX</span></a></li>
68
54
  <li class="current"> <a href="group__GRAS__API.html"><span>GRAS</span></a></li>
69
55
  <li> <a href="group__AMOK__API.html"><span>AMOK</span></a></li>
70
56
  <li> <a href="group__SMPI__API.html"><span>SMPI</span></a></li>
115
101
<div class="header">
116
102
  <div class="headertitle">
117
103
<div class="title">Lesson 8: Handling errors through exceptions </div>  </div>
118
 
</div><!--header-->
 
104
</div>
119
105
<div class="contents">
120
106
<div class="textblock"><h2><a class="anchor" id="GRAS_tut_tour_exceptions_toc"></a>
121
107
Table of Contents</h2>
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>
137
 
<div class="fragment"><pre class="fragment">TRY{ 
138
 
  /* your code */ 
 
123
<div class="fragment"><pre class="fragment">TRY{
 
124
  /* your code */
139
125
}
140
126
CATCH(e) {
141
127
  /* error handling code */
252
238
  }
253
239
 
254
240
  <span class="keywordflow">while</span> (!globals-&gt;killed) {
255
 
    <a class="code" href="group__GRAS__msg__exchange.html#ga734f74309ee66358e60f6926084e46c5" title="Handle an incomming message or timer (or wait up to timeOut seconds)">gras_msg_handle</a>(-1);        <span class="comment">/* blocking */</span>
 
241
    <a class="code" href="group__GRAS__msg__exchange.html#ga734f74309ee66358e60f6926084e46c5" title="Handle an incoming message or timer (or wait up to timeOut seconds)">gras_msg_handle</a>(-1);        <span class="comment">/* blocking */</span>
256
242
  }
257
243
 
258
244
  <a class="code" href="group__GRAS__API.html#gaee47a46ba8da34d67242a80552252dbe" title="Finalize the gras mechanisms.">gras_exit</a>();
300
286
  <span class="keywordflow">return</span> 0;
301
287
}
302
288
</pre></div><p>Go to <a class="el" href="GRAS_tut_tour_simpledata.html">Lesson 9: Exchanging simple data</a> </p>
303
 
</div></div><!-- contents -->
 
289
</div></div>
304
290
<p>
305
291
<hr>
306
292
 
311
297
Back to the main Simgrid Documentation page</b></a>
312
298
</td>
313
299
<td align=middle>
314
 
<small>The version of <a href="http://simgrid.gforge.inria.fr">SimGrid</a> documented here is v3.7.<br/>
 
300
<small>The version of <a href="http://simgrid.gforge.inria.fr">SimGrid</a> documented here is v3.7.1.<br/>
315
301
Documentation of other versions can be found in their respective
316
302
archive files (directory doc/html).
317
303
</td>