/usr/share/gtk-doc/html/cogl-2.0-experimental/cogl-2.0-experimental-Exception-handling.html is in libcogl-doc 1.22.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Exception handling: Cogl 2.0 Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Cogl 2.0 Reference Manual">
<link rel="up" href="cogl-general-apis.html" title="General API concepts">
<link rel="prev" href="cogl-2.0-experimental-The-Object-Interface.html" title="The Object Interface">
<link rel="next" href="cogl-2.0-experimental-Common-Types.html" title="Common Types">
<meta name="generator" content="GTK-Doc V1.25 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts">
<a href="#" class="shortcut">Top</a><span id="nav_description"> <span class="dim">|</span>
<a href="#cogl-2.0-experimental-Exception-handling.description" class="shortcut">Description</a></span>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="cogl-general-apis.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="cogl-2.0-experimental-The-Object-Interface.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="cogl-2.0-experimental-Common-Types.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="cogl-2.0-experimental-Exception-handling"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="cogl-2.0-experimental-Exception-handling.top_of_page"></a>Exception handling</span></h2>
<p>Exception handling — A way for Cogl to throw exceptions</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="cogl-2.0-experimental-Exception-handling.functions"></a><h2>Functions</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="functions_return">
<col class="functions_name">
</colgroup>
<tbody>
<tr>
<td class="function_type">
<a class="link" href="cogl-2.0-experimental-Common-Types.html#CoglBool" title="CoglBool"><span class="returnvalue">CoglBool</span></a>
</td>
<td class="function_name">
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-matches" title="cogl_error_matches ()">cogl_error_matches</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-free" title="cogl_error_free ()">cogl_error_free</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="returnvalue">CoglError</span></a> *
</td>
<td class="function_name">
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-copy" title="cogl_error_copy ()">cogl_error_copy</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#COGL-GLIB-ERROR:CAPS" title="COGL_GLIB_ERROR()">COGL_GLIB_ERROR</a><span class="c_punctuation">()</span>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="cogl-2.0-experimental-Exception-handling.other"></a><h2>Types and Values</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="name">
<col class="description">
</colgroup>
<tbody><tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError">CoglError</a></td>
</tr></tbody>
</table></div>
</div>
<div class="refsect1">
<a name="cogl-2.0-experimental-Exception-handling.description"></a><h2>Description</h2>
<p>As a general rule Cogl shields non-recoverable errors from
developers, such as most heap allocation failures (unless for
exceptionally large resources which we might reasonably expect to
fail) and this reduces the burden on developers.</p>
<p>There are some Cogl apis though that can fail for exceptional
reasons that can also potentially be recovered from at runtime
and for these apis we use a standard convention for reporting
runtime recoverable errors.</p>
<p>As an example if we look at the <a class="link" href="cogl-2.0-experimental-The-Top-Level-Context.html#cogl-context-new" title="cogl_context_new ()"><code class="function">cogl_context_new()</code></a> api which
takes an error argument:</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2</pre></td>
<td class="listing_code"><pre class="programlisting">CoglContext <span class="gtkdoc opt">*</span>
<span class="function"><a href="cogl-2.0-experimental-The-Top-Level-Context.html#cogl-context-new">cogl_context_new</a></span> <span class="gtkdoc opt">(</span>CoglDisplay <span class="gtkdoc opt">*</span>display<span class="gtkdoc opt">,</span> CoglError <span class="gtkdoc opt">**</span>error<span class="gtkdoc opt">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<p>A caller interested in catching any runtime error when creating a
new <a class="link" href="cogl-2.0-experimental-The-Top-Level-Context.html#CoglContext" title="CoglContext"><span class="type">CoglContext</span></a> would pass the address of a <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> pointer
that has first been initialized to <code class="literal">NULL</code> as follows:</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4</pre></td>
<td class="listing_code"><pre class="programlisting">CoglError <span class="gtkdoc opt">*</span>error <span class="gtkdoc opt">=</span> NULL<span class="gtkdoc opt">;</span>
CoglContext <span class="gtkdoc opt">*</span>context<span class="gtkdoc opt">;</span>
context <span class="gtkdoc opt">=</span> <span class="function"><a href="cogl-2.0-experimental-The-Top-Level-Context.html#cogl-context-new">cogl_context_new</a></span> <span class="gtkdoc opt">(</span>NULL<span class="gtkdoc opt">, &</span>error<span class="gtkdoc opt">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<p>The return status should usually be enough to determine if there
was an error set (in this example we can check if context == <code class="literal">NULL</code>)
but if it's not possible to tell from the function's return status
you can instead look directly at the error pointer which you
initialized to <code class="literal">NULL</code>. In this example we now check the error,
report any error to the user, free the error and then simply
abort without attempting to recover.</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="keyword">if</span> <span class="gtkdoc opt">(</span>context <span class="gtkdoc opt">==</span> NULL<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
<span class="function">fprintf</span> <span class="gtkdoc opt">(</span>stderr<span class="gtkdoc opt">,</span> <span class="string">"Failed to create a Cogl context: %s</span><span class="gtkdoc esc">\n</span><span class="string">"</span><span class="gtkdoc opt">,</span>
error<span class="gtkdoc opt">-></span>message<span class="gtkdoc opt">);</span>
<span class="function"><a href="cogl-2.0-experimental-Exception-handling.html#cogl-error-free">cogl_error_free</a></span> <span class="gtkdoc opt">(</span>error<span class="gtkdoc opt">);</span>
<span class="function">abort</span> <span class="gtkdoc opt">();</span>
<span class="gtkdoc opt">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<p>All Cogl APIs that accept an error argument can also be passed a
<code class="literal">NULL</code> pointer. In this case if an exceptional error condition is hit
then Cogl will simply log the error message and abort the
application. This can be compared to language execeptions where the
developer has not attempted to catch the exception. This means the
above example is essentially redundant because it's what Cogl would
have done automatically and so, similarly, if your application has
no way to recover from a particular error you might just as well
pass a <code class="literal">NULL</code> <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> pointer to save a bit of typing.</p>
<div class="note">If you are used to using the GLib API you will probably
recognize that <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> is just like a <span class="type">GError</span>. In fact if Cogl
has been built with --enable-glib then it is safe to cast a
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> to a <span class="type">GError</span>.</div>
<div class="note">An important detail to be aware of if you are used to using
GLib's GError API is that Cogl deviates from the GLib GError
conventions in one noteable way which is that a <code class="literal">NULL</code> error pointer
does not mean you want to ignore the details of an error, it means
you are not trying to catch any exceptional errors the function might
throw which will result in the program aborting with a log message
if an error is thrown.</div>
</div>
<div class="refsect1">
<a name="cogl-2.0-experimental-Exception-handling.functions_details"></a><h2>Functions</h2>
<div class="refsect2">
<a name="cogl-error-matches"></a><h3>cogl_error_matches ()</h3>
<pre class="programlisting"><a class="link" href="cogl-2.0-experimental-Common-Types.html#CoglBool" title="CoglBool"><span class="returnvalue">CoglBool</span></a>
cogl_error_matches (<em class="parameter"><code><a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> *error</code></em>,
<em class="parameter"><code><span class="type">uint32_t</span> domain</code></em>,
<em class="parameter"><code><span class="type">int</span> code</code></em>);</pre>
<p>Returns <code class="literal">TRUE</code> if error matches <em class="parameter"><code>domain</code></em>
and <em class="parameter"><code>code</code></em>
, <code class="literal">FALSE</code> otherwise.
In particular, when error is <code class="literal">NULL</code>, FALSE will be returned.</p>
<div class="refsect3">
<a name="cogl-error-matches.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p>A <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> thrown by the Cogl api or <code class="literal">NULL</code></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>domain</p></td>
<td class="parameter_description"><p>The error domain</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>code</p></td>
<td class="parameter_description"><p>The error code</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="cogl-error-matches.returns"></a><h4>Returns</h4>
<p> whether the <em class="parameter"><code>error</code></em>
corresponds to the given <em class="parameter"><code>domain</code></em>
and <em class="parameter"><code>code</code></em>
.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="cogl-error-free"></a><h3>cogl_error_free ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
cogl_error_free (<em class="parameter"><code><a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> *error</code></em>);</pre>
<p>Frees a <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> and associated resources.</p>
<div class="refsect3">
<a name="cogl-error-free.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p>A <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> thrown by the Cogl api</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="cogl-error-copy"></a><h3>cogl_error_copy ()</h3>
<pre class="programlisting"><a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="returnvalue">CoglError</span></a> *
cogl_error_copy (<em class="parameter"><code><a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> *error</code></em>);</pre>
<p>Makes a copy of <em class="parameter"><code>error</code></em>
which can later be freed using
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-free" title="cogl_error_free ()"><code class="function">cogl_error_free()</code></a>.</p>
<div class="refsect3">
<a name="cogl-error-copy.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p>A <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> thrown by the Cogl api</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="cogl-error-copy.returns"></a><h4>Returns</h4>
<p> A newly allocated <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> initialized to match the
contents of <em class="parameter"><code>error</code></em>
.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="COGL-GLIB-ERROR:CAPS"></a><h3>COGL_GLIB_ERROR()</h3>
<pre class="programlisting">#define COGL_GLIB_ERROR(COGL_ERROR) ((CoglError *)COGL_ERROR)
</pre>
<p>Simply casts a <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> to a <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a></p>
<p>If Cogl is built with GLib support then it can safely be assumed
that a CoglError is a GError and can be used directly with the
GError api.</p>
<div class="refsect3">
<a name="COGL-GLIB-ERROR.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>COGL_ERROR</p></td>
<td class="parameter_description"><p>A <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="type">CoglError</span></a> thrown by the Cogl api or <code class="literal">NULL</code></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
</div>
<div class="refsect1">
<a name="cogl-2.0-experimental-Exception-handling.other_details"></a><h2>Types and Values</h2>
<div class="refsect2">
<a name="CoglError"></a><h3>CoglError</h3>
<pre class="programlisting">#define CoglError GError
</pre>
<div class="refsect3">
<a name="CoglError.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>domain</p></td>
<td class="parameter_description"><p>A high-level domain identifier for the error</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>code</p></td>
<td class="parameter_description"><p>A specific error code within a specified domain</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>message</p></td>
<td class="parameter_description"><p>A human readable error message</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.25</div>
</body>
</html>
|