/usr/share/gtk-doc/html/cogl-2.0-experimental/cogl-2.0-experimental-Exception-handling.html is in libcogl-doc 1.16.2-1.
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 | <!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</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.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.19 (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="2">
<tr valign="middle">
<td><a accesskey="p" href="cogl-2.0-experimental-The-Object-Interface.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="cogl-general-apis.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">Cogl 2.0 Reference Manual</th>
<td><a accesskey="n" href="cogl-2.0-experimental-Common-Types.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#cogl-2.0-experimental-Exception-handling.synopsis" class="shortcut">Top</a>
|
<a href="#cogl-2.0-experimental-Exception-handling.description" class="shortcut">Description</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 valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="cogl-2.0-experimental-Exception-handling.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">#define <a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError">CoglError</a>
<a class="link" href="cogl-2.0-experimental-Common-Types.html#CoglBool" title="CoglBool"><span class="returnvalue">CoglBool</span></a> <a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-matches" title="cogl_error_matches ()">cogl_error_matches</a> (<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>);
<span class="returnvalue">void</span> <a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-free" title="cogl_error_free ()">cogl_error_free</a> (<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>);
<a class="link" href="cogl-2.0-experimental-Exception-handling.html#CoglError" title="CoglError"><span class="returnvalue">CoglError</span></a> * <a class="link" href="cogl-2.0-experimental-Exception-handling.html#cogl-error-copy" title="cogl_error_copy ()">cogl_error_copy</a> (<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>);
#define <a class="link" href="cogl-2.0-experimental-Exception-handling.html#COGL-GLIB-ERROR:CAPS" title="COGL_GLIB_ERROR()">COGL_GLIB_ERROR</a> (COGL_ERROR)
</pre>
</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"><pre class="programlisting">
CoglContext *
cogl_context_new (CoglDisplay *display, CoglError **error);
</pre></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>
<p>
</p>
<div class="informalexample"><pre class="programlisting">
CoglError *error = NULL;
CoglContext *context;
context = cogl_context_new (NULL, &error);
</pre></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>
<p>
</p>
<div class="informalexample"><pre class="programlisting">
if (context == NULL)
{
fprintf (stderr, "Failed to create a Cogl context: %s\n",
error->message);
cogl_error_free (error);
abort ();
}
</pre></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>
<p>
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>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>
<p>
</p>
<p>
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>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>
<p>
</p>
</div>
<div class="refsect1">
<a name="cogl-2.0-experimental-Exception-handling.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="CoglError"></a><h3>CoglError</h3>
<pre class="programlisting">#define CoglError GError
</pre>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>A high-level domain identifier for the error</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>code</code></em> :</span></p></td>
<td>A specific error code within a specified domain</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>message</code></em> :</span></p></td>
<td>A human readable error message</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<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="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>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>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
<td>The error domain</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>code</code></em> :</span></p></td>
<td>The error code</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>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>.</td>
</tr>
</tbody>
</table></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="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>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</td>
</tr></tbody>
</table></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="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>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</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>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>.</td>
</tr>
</tbody>
</table></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="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>COGL_ERROR</code></em> :</span></p></td>
<td>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>
</td>
</tr></tbody>
</table></div>
</div>
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.19</div>
</body>
</html>
|