PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/glib-2.25.17/docs/reference/glib/html/glib-Error-Reporting.html

https://bitbucket.org/ArminW/3p-glib
HTML | 1026 lines | 1015 code | 11 blank | 0 comment | 0 complexity | 69f4f01d0b03c5fc7ff16887ee124d1c MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>Error Reporting</title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
  7. <link rel="home" href="index.html" title="GLib Reference Manual">
  8. <link rel="up" href="glib-core.html" title="GLib Core Application Support">
  9. <link rel="prev" href="glib-IO-Channels.html" title="IO Channels">
  10. <link rel="next" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions">
  11. <meta name="generator" content="GTK-Doc V1.15.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
  16. <tr valign="middle">
  17. <td><a accesskey="p" href="glib-IO-Channels.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
  18. <td><a accesskey="u" href="glib-core.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
  19. <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
  20. <th width="100%" align="center">GLib Reference Manual</th>
  21. <td><a accesskey="n" href="glib-Warnings-and-Assertions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
  22. </tr>
  23. <tr><td colspan="5" class="shortcuts">
  24. <a href="#glib-Error-Reporting.synopsis" class="shortcut">Top</a>
  25.  | 
  26. <a href="#glib-Error-Reporting.description" class="shortcut">Description</a>
  27. </td></tr>
  28. </table>
  29. <div class="refentry">
  30. <a name="glib-Error-Reporting"></a><div class="titlepage"></div>
  31. <div class="refnamediv"><table width="100%"><tr>
  32. <td valign="top">
  33. <h2><span class="refentrytitle"><a name="glib-Error-Reporting.top_of_page"></a>Error Reporting</span></h2>
  34. <p>Error Reporting a system for reporting errors</p>
  35. </td>
  36. <td valign="top" align="right"></td>
  37. </tr></table></div>
  38. <div class="refsynopsisdiv">
  39. <a name="glib-Error-Reporting.synopsis"></a><h2>Synopsis</h2>
  40. <pre class="synopsis">
  41. #include &lt;glib.h&gt;
  42. <a class="link" href="glib-Error-Reporting.html#GError" title="GError">GError</a>;
  43. <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> * <a class="link" href="glib-Error-Reporting.html#g-error-new" title="g_error_new ()">g_error_new</a> (<em class="parameter"><code><a class="link" href="glib-Quarks.html#GQuark" title="GQuark"><span class="type">GQuark</span></a> domain</code></em>,
  44. <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> code</code></em>,
  45. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *format</code></em>,
  46. <em class="parameter"><code>...</code></em>);
  47. <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> * <a class="link" href="glib-Error-Reporting.html#g-error-new-literal" title="g_error_new_literal ()">g_error_new_literal</a> (<em class="parameter"><code><a class="link" href="glib-Quarks.html#GQuark" title="GQuark"><span class="type">GQuark</span></a> domain</code></em>,
  48. <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> code</code></em>,
  49. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *message</code></em>);
  50. <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> * <a class="link" href="glib-Error-Reporting.html#g-error-new-valist" title="g_error_new_valist ()">g_error_new_valist</a> (<em class="parameter"><code><a class="link" href="glib-Quarks.html#GQuark" title="GQuark"><span class="type">GQuark</span></a> domain</code></em>,
  51. <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> code</code></em>,
  52. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *format</code></em>,
  53. <em class="parameter"><code><span class="type">va_list</span> args</code></em>);
  54. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-error-free" title="g_error_free ()">g_error_free</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> *error</code></em>);
  55. <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> * <a class="link" href="glib-Error-Reporting.html#g-error-copy" title="g_error_copy ()">g_error_copy</a> (<em class="parameter"><code>const <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> *error</code></em>);
  56. <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Error-Reporting.html#g-error-matches" title="g_error_matches ()">g_error_matches</a> (<em class="parameter"><code>const <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> *error</code></em>,
  57. <em class="parameter"><code><a class="link" href="glib-Quarks.html#GQuark" title="GQuark"><span class="type">GQuark</span></a> domain</code></em>,
  58. <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> code</code></em>);
  59. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-set-error" title="g_set_error ()">g_set_error</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> **err</code></em>,
  60. <em class="parameter"><code><a class="link" href="glib-Quarks.html#GQuark" title="GQuark"><span class="type">GQuark</span></a> domain</code></em>,
  61. <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> code</code></em>,
  62. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *format</code></em>,
  63. <em class="parameter"><code>...</code></em>);
  64. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-set-error-literal" title="g_set_error_literal ()">g_set_error_literal</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> **err</code></em>,
  65. <em class="parameter"><code><a class="link" href="glib-Quarks.html#GQuark" title="GQuark"><span class="type">GQuark</span></a> domain</code></em>,
  66. <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> code</code></em>,
  67. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *message</code></em>);
  68. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-propagate-error" title="g_propagate_error ()">g_propagate_error</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> **dest</code></em>,
  69. <em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> *src</code></em>);
  70. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-clear-error" title="g_clear_error ()">g_clear_error</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> **err</code></em>);
  71. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-prefix-error" title="g_prefix_error ()">g_prefix_error</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> **err</code></em>,
  72. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *format</code></em>,
  73. <em class="parameter"><code>...</code></em>);
  74. <span class="returnvalue">void</span> <a class="link" href="glib-Error-Reporting.html#g-propagate-prefixed-error" title="g_propagate_prefixed_error ()">g_propagate_prefixed_error</a> (<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> **dest</code></em>,
  75. <em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> *src</code></em>,
  76. <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *format</code></em>,
  77. <em class="parameter"><code>...</code></em>);
  78. </pre>
  79. </div>
  80. <div class="refsect1">
  81. <a name="glib-Error-Reporting.description"></a><h2>Description</h2>
  82. <p>
  83. GLib provides a standard method of reporting errors from a called function to
  84. the calling code. (This is the same problem solved by exceptions in other
  85. languages.) It's important to understand that this method is both a
  86. <span class="emphasis"><em>data type</em></span> (the <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> object) and a <span class="emphasis"><em>set of
  87. rules.</em></span> If you use <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> incorrectly, then your code will not
  88. properly interoperate with other code that uses <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>, and users of your API
  89. will probably get confused.
  90. </p>
  91. <p>
  92. First and foremost: <span class="emphasis"><em><a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> should only be used to report
  93. recoverable runtime errors, never to report programming errors.</em></span> If
  94. the programmer has screwed up, then you should use <a class="link" href="glib-Message-Logging.html#g-warning" title="g_warning ()"><code class="function">g_warning()</code></a>,
  95. <a class="link" href="glib-Warnings-and-Assertions.html#g-return-if-fail" title="g_return_if_fail()"><code class="function">g_return_if_fail()</code></a>, <a class="link" href="glib-Testing.html#g-assert" title="g_assert()"><code class="function">g_assert()</code></a>, <a class="link" href="glib-Message-Logging.html#g-error" title="g_error ()"><code class="function">g_error()</code></a>, or some similar facility.
  96. (Incidentally, remember that the <a class="link" href="glib-Message-Logging.html#g-error" title="g_error ()"><code class="function">g_error()</code></a> function should
  97. <span class="emphasis"><em>only</em></span> be used for programming errors, it should not be used
  98. to print any error reportable via <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>.)
  99. </p>
  100. <p>
  101. Examples of recoverable runtime errors are "file not found" or "failed to parse
  102. input." Examples of programming errors are "NULL passed to <code class="function">strcmp()</code>" or
  103. "attempted to free the same pointer twice." These two kinds of errors are
  104. fundamentally different: runtime errors should be handled or reported to the
  105. user, programming errors should be eliminated by fixing the bug in the program.
  106. This is why most functions in GLib and GTK+ do not use the <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> facility.
  107. </p>
  108. <p>
  109. Functions that can fail take a return location for a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> as their last argument.
  110. For example:
  111. </p>
  112. <div class="informalexample">
  113. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  114. <tbody>
  115. <tr>
  116. <td class="listing_lines" align="right"><pre>1
  117. 2
  118. 3
  119. 4</pre></td>
  120. <td class="listing_code"><pre class="programlisting"><span class="usertype">gboolean</span><span class="normal"> </span><span class="function"><a href="glib-File-Utilities.html#g-file-get-contents">g_file_get_contents</a></span><span class="normal"> </span><span class="symbol">(</span><span class="keyword">const</span><span class="normal"> </span><span class="usertype">gchar</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">filename</span><span class="symbol">,</span>
  121. <span class="normal"> </span><span class="usertype">gchar</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">contents</span><span class="symbol">,</span>
  122. <span class="normal"> </span><span class="usertype">gsize</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">length</span><span class="symbol">,</span>
  123. <span class="normal"> </span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">error</span><span class="symbol">);</span></pre></td>
  124. </tr>
  125. </tbody>
  126. </table>
  127. </div>
  128. <p>
  129. If you pass a non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> value for the <code class="literal">error</code> argument, it should
  130. point to a location where an error can be placed. For example:
  131. </p>
  132. <div class="informalexample">
  133. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  134. <tbody>
  135. <tr>
  136. <td class="listing_lines" align="right"><pre>1
  137. 2
  138. 3
  139. 4
  140. 5
  141. 6
  142. 7
  143. 8
  144. 9
  145. 10
  146. 11
  147. 12
  148. 13
  149. 14
  150. 15
  151. 16</pre></td>
  152. <td class="listing_code"><pre class="programlisting"><span class="usertype">gchar</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">contents</span><span class="symbol">;</span>
  153. <span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
  154. <span class="function"><a href="glib-File-Utilities.html#g-file-get-contents">g_file_get_contents</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"foo.txt"</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">contents</span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">err</span><span class="symbol">);</span>
  155. <span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">((</span><span class="normal">contents </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">&amp;&amp;</span><span class="normal"> err </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">contents </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">&amp;&amp;</span><span class="normal"> err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">));</span>
  156. <span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">)</span>
  157. <span class="normal"> </span><span class="cbracket">{</span>
  158. <span class="normal"> </span><span class="comment">/* Report error to user, and free error */</span>
  159. <span class="normal"> </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">contents </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
  160. <span class="normal"> </span><span class="function">fprintf</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">stderr</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Unable to read file: %s</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> err</span><span class="symbol">-&gt;</span><span class="normal">message</span><span class="symbol">);</span>
  161. <span class="normal"> </span><span class="function"><a href="glib-Error-Reporting.html#g-error-free">g_error_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err</span><span class="symbol">);</span>
  162. <span class="normal"> </span><span class="cbracket">}</span>
  163. <span class="keyword">else</span>
  164. <span class="normal"> </span><span class="cbracket">{</span>
  165. <span class="normal"> </span><span class="comment">/* Use file contents */</span>
  166. <span class="normal"> </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">contents </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
  167. <span class="normal"> </span><span class="cbracket">}</span></pre></td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. </div>
  172. <p>
  173. Note that <code class="literal">err != NULL</code> in this example is a
  174. <span class="emphasis"><em>reliable</em></span> indicator of whether
  175. <a class="link" href="glib-File-Utilities.html#g-file-get-contents" title="g_file_get_contents ()"><code class="function">g_file_get_contents()</code></a> failed. Additionally, <a class="link" href="glib-File-Utilities.html#g-file-get-contents" title="g_file_get_contents ()"><code class="function">g_file_get_contents()</code></a> returns
  176. a boolean which indicates whether it was successful.
  177. </p>
  178. <p>
  179. Because <a class="link" href="glib-File-Utilities.html#g-file-get-contents" title="g_file_get_contents ()"><code class="function">g_file_get_contents()</code></a> returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> on failure, if you are only
  180. interested in whether it failed and don't need to display an error message, you
  181. can pass <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> for the <code class="literal">error</code> argument:
  182. </p>
  183. <div class="informalexample">
  184. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  185. <tbody>
  186. <tr>
  187. <td class="listing_lines" align="right"><pre>1
  188. 2
  189. 3
  190. 4</pre></td>
  191. <td class="listing_code"><pre class="programlisting"><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="glib-File-Utilities.html#g-file-get-contents">g_file_get_contents</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"foo.txt"</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">contents</span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">))</span><span class="normal"> </span><span class="comment">/* ignore errors */</span>
  192. <span class="normal"> </span><span class="comment">/* no error occurred */</span><span class="normal"> </span><span class="symbol">;</span>
  193. <span class="keyword">else</span>
  194. <span class="normal"> </span><span class="comment">/* error */</span><span class="normal"> </span><span class="symbol">;</span></pre></td>
  195. </tr>
  196. </tbody>
  197. </table>
  198. </div>
  199. <p>
  200. </p>
  201. <p>
  202. The <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> object contains three fields: <code class="literal">domain</code> indicates
  203. the module the error-reporting function is located in, <code class="literal">code</code>
  204. indicates the specific error that occurred, and <code class="literal">message</code> is a
  205. user-readable error message with as many details as possible. Several functions
  206. are provided to deal with an error received from a called function:
  207. <a class="link" href="glib-Error-Reporting.html#g-error-matches" title="g_error_matches ()"><code class="function">g_error_matches()</code></a> returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the error matches a given domain and code,
  208. <a class="link" href="glib-Error-Reporting.html#g-propagate-error" title="g_propagate_error ()"><code class="function">g_propagate_error()</code></a> copies an error into an error location (so the calling
  209. function will receive it), and <a class="link" href="glib-Error-Reporting.html#g-clear-error" title="g_clear_error ()"><code class="function">g_clear_error()</code></a> clears an error location by
  210. freeing the error and resetting the location to <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. To display an error to the
  211. user, simply display <code class="literal">error-&gt;message</code>, perhaps along with
  212. additional context known only to the calling function (the file being opened, or
  213. whatever -- though in the <a class="link" href="glib-File-Utilities.html#g-file-get-contents" title="g_file_get_contents ()"><code class="function">g_file_get_contents()</code></a> case,
  214. <code class="literal">error-&gt;message</code> already contains a filename).
  215. </p>
  216. <p>
  217. When implementing a function that can report errors, the basic tool is
  218. <a class="link" href="glib-Error-Reporting.html#g-set-error" title="g_set_error ()"><code class="function">g_set_error()</code></a>. Typically, if a fatal error occurs you want to <a class="link" href="glib-Error-Reporting.html#g-set-error" title="g_set_error ()"><code class="function">g_set_error()</code></a>,
  219. then return immediately. <a class="link" href="glib-Error-Reporting.html#g-set-error" title="g_set_error ()"><code class="function">g_set_error()</code></a> does nothing if the error location passed
  220. to it is <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. Here's an example:
  221. </p>
  222. <div class="informalexample">
  223. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  224. <tbody>
  225. <tr>
  226. <td class="listing_lines" align="right"><pre>1
  227. 2
  228. 3
  229. 4
  230. 5
  231. 6
  232. 7
  233. 8
  234. 9
  235. 10
  236. 11
  237. 12
  238. 13
  239. 14
  240. 15
  241. 16
  242. 17</pre></td>
  243. <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gint">gint</a></span>
  244. <span class="function">foo_open_file</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">error</span><span class="symbol">)</span>
  245. <span class="cbracket">{</span>
  246. <span class="normal"> </span><span class="usertype">gint</span><span class="normal"> fd</span><span class="symbol">;</span>
  247. <span class="normal"> fd </span><span class="symbol">=</span><span class="normal"> </span><span class="function">open</span><span class="normal"> </span><span class="symbol">(</span><span class="string">"file.txt"</span><span class="symbol">,</span><span class="normal"> O_RDONLY</span><span class="symbol">);</span>
  248. <span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">fd </span><span class="symbol">&lt;</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
  249. <span class="normal"> </span><span class="cbracket">{</span>
  250. <span class="normal"> </span><span class="function"><a href="glib-Error-Reporting.html#g-set-error">g_set_error</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">error</span><span class="symbol">,</span>
  251. <span class="normal"> FOO_ERROR</span><span class="symbol">,</span><span class="normal"> </span><span class="comment">/* error domain */</span>
  252. <span class="normal"> FOO_ERROR_BLAH</span><span class="symbol">,</span><span class="normal"> </span><span class="comment">/* error code */</span>
  253. <span class="normal"> </span><span class="string">"Failed to open file: %s"</span><span class="symbol">,</span><span class="normal"> </span><span class="comment">/* error message format string */</span>
  254. <span class="normal"> </span><span class="function"><a href="glib-String-Utility-Functions.html#g-strerror">g_strerror</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">errno</span><span class="symbol">));</span>
  255. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="symbol">-</span><span class="number">1</span><span class="symbol">;</span>
  256. <span class="normal"> </span><span class="cbracket">}</span>
  257. <span class="normal"> </span><span class="keyword">else</span>
  258. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> fd</span><span class="symbol">;</span>
  259. <span class="cbracket">}</span></pre></td>
  260. </tr>
  261. </tbody>
  262. </table>
  263. </div>
  264. <p>
  265. </p>
  266. <p>
  267. Things are somewhat more complicated if you yourself call another function that
  268. can report a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>. If the sub-function indicates fatal errors in some way
  269. other than reporting a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>, such as by returning <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> on success, you can
  270. simply do the following:
  271. </p>
  272. <div class="informalexample">
  273. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  274. <tbody>
  275. <tr>
  276. <td class="listing_lines" align="right"><pre>1
  277. 2
  278. 3
  279. 4
  280. 5
  281. 6
  282. 7
  283. 8
  284. 9
  285. 10
  286. 11
  287. 12
  288. 13</pre></td>
  289. <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gboolean">gboolean</a></span>
  290. <span class="function">my_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">err</span><span class="symbol">)</span>
  291. <span class="cbracket">{</span>
  292. <span class="normal"> </span><span class="function"><a href="glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
  293. <span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(!</span><span class="function">sub_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err</span><span class="symbol">))</span>
  294. <span class="normal"> </span><span class="cbracket">{</span>
  295. <span class="normal"> </span><span class="comment">/* assert that error was set by the sub-function */</span>
  296. <span class="normal"> </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
  297. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">;</span>
  298. <span class="normal"> </span><span class="cbracket">}</span>
  299. <span class="normal"> </span><span class="comment">/* otherwise continue, no error occurred */</span>
  300. <span class="normal"> </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
  301. <span class="cbracket">}</span></pre></td>
  302. </tr>
  303. </tbody>
  304. </table>
  305. </div>
  306. <p>
  307. </p>
  308. <p>
  309. If the sub-function does not indicate errors other than by reporting a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>,
  310. you need to create a temporary <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> since the passed-in one may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>.
  311. <a class="link" href="glib-Error-Reporting.html#g-propagate-error" title="g_propagate_error ()"><code class="function">g_propagate_error()</code></a> is intended for use in this case.
  312. </p>
  313. <div class="informalexample">
  314. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  315. <tbody>
  316. <tr>
  317. <td class="listing_lines" align="right"><pre>1
  318. 2
  319. 3
  320. 4
  321. 5
  322. 6
  323. 7
  324. 8
  325. 9
  326. 10
  327. 11
  328. 12
  329. 13
  330. 14
  331. 15
  332. 16
  333. 17</pre></td>
  334. <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gboolean">gboolean</a></span>
  335. <span class="function">my_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">err</span><span class="symbol">)</span>
  336. <span class="cbracket">{</span>
  337. <span class="normal"> </span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">tmp_error</span><span class="symbol">;</span>
  338. <span class="normal"> </span><span class="function"><a href="glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
  339. <span class="normal"> tmp_error </span><span class="symbol">=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
  340. <span class="normal"> </span><span class="function">sub_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">tmp_error</span><span class="symbol">);</span>
  341. <span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">tmp_error </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">)</span>
  342. <span class="normal"> </span><span class="cbracket">{</span>
  343. <span class="normal"> </span><span class="comment">/* store tmp_error in err, if err != NULL,</span>
  344. <span class="comment"> * otherwise call g_error_free() on tmp_error</span>
  345. <span class="comment"> */</span>
  346. <span class="normal"> </span><span class="function"><a href="glib-Error-Reporting.html#g-propagate-error">g_propagate_error</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err</span><span class="symbol">,</span><span class="normal"> tmp_error</span><span class="symbol">);</span>
  347. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">;</span>
  348. <span class="normal"> </span><span class="cbracket">}</span>
  349. <span class="normal"> </span><span class="comment">/* otherwise continue, no error occurred */</span>
  350. <span class="cbracket">}</span></pre></td>
  351. </tr>
  352. </tbody>
  353. </table>
  354. </div>
  355. <p>
  356. </p>
  357. <p>
  358. Error pileups are always a bug. For example, this code is incorrect:
  359. </p>
  360. <div class="informalexample">
  361. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  362. <tbody>
  363. <tr>
  364. <td class="listing_lines" align="right"><pre>1
  365. 2
  366. 3
  367. 4
  368. 5
  369. 6
  370. 7
  371. 8
  372. 9
  373. 10
  374. 11
  375. 12
  376. 13
  377. 14</pre></td>
  378. <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gboolean">gboolean</a></span>
  379. <span class="function">my_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">err</span><span class="symbol">)</span>
  380. <span class="cbracket">{</span>
  381. <span class="normal"> </span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">tmp_error</span><span class="symbol">;</span>
  382. <span class="normal"> </span><span class="function"><a href="glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
  383. <span class="normal"> tmp_error </span><span class="symbol">=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
  384. <span class="normal"> </span><span class="function">sub_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">tmp_error</span><span class="symbol">);</span>
  385. <span class="normal"> </span><span class="function">other_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">tmp_error</span><span class="symbol">);</span>
  386. <span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">tmp_error </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">)</span>
  387. <span class="normal"> </span><span class="cbracket">{</span>
  388. <span class="normal"> </span><span class="function"><a href="glib-Error-Reporting.html#g-propagate-error">g_propagate_error</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err</span><span class="symbol">,</span><span class="normal"> tmp_error</span><span class="symbol">);</span>
  389. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">;</span>
  390. <span class="normal"> </span><span class="cbracket">}</span>
  391. <span class="cbracket">}</span></pre></td>
  392. </tr>
  393. </tbody>
  394. </table>
  395. </div>
  396. <p>
  397. <code class="literal">tmp_error</code> should be checked immediately after
  398. <code class="function"><code class="function">sub_function_that_can_fail()</code></code>, and either cleared or propagated upward. The rule
  399. is: <span class="emphasis"><em>after each error, you must either handle the error, or return it to the
  400. calling function</em></span>. Note that passing <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> for the error location is the
  401. equivalent of handling an error by always doing nothing about it. So the
  402. following code is fine, assuming errors in <code class="function"><code class="function">sub_function_that_can_fail()</code></code> are not
  403. fatal to <code class="function"><code class="function">my_function_that_can_fail()</code></code>:
  404. </p>
  405. <div class="informalexample">
  406. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  407. <tbody>
  408. <tr>
  409. <td class="listing_lines" align="right"><pre>1
  410. 2
  411. 3
  412. 4
  413. 5
  414. 6
  415. 7
  416. 8
  417. 9
  418. 10
  419. 11
  420. 12
  421. 13
  422. 14</pre></td>
  423. <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gboolean">gboolean</a></span>
  424. <span class="function">my_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">err</span><span class="symbol">)</span>
  425. <span class="cbracket">{</span>
  426. <span class="normal"> </span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">tmp_error</span><span class="symbol">;</span>
  427. <span class="normal"> </span><span class="function"><a href="glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a> </span><span class="symbol">||</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">err </span><span class="symbol">==</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
  428. <span class="normal"> </span><span class="function">sub_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span><span class="normal"> </span><span class="comment">/* ignore errors */</span>
  429. <span class="normal"> tmp_error </span><span class="symbol">=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
  430. <span class="normal"> </span><span class="function">other_function_that_can_fail</span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">tmp_error</span><span class="symbol">);</span>
  431. <span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">tmp_error </span><span class="symbol">!=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">)</span>
  432. <span class="normal"> </span><span class="cbracket">{</span>
  433. <span class="normal"> </span><span class="function"><a href="glib-Error-Reporting.html#g-propagate-error">g_propagate_error</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">err</span><span class="symbol">,</span><span class="normal"> tmp_error</span><span class="symbol">);</span>
  434. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">;</span>
  435. <span class="normal"> </span><span class="cbracket">}</span>
  436. <span class="cbracket">}</span></pre></td>
  437. </tr>
  438. </tbody>
  439. </table>
  440. </div>
  441. <p>
  442. </p>
  443. <p>
  444. Note that passing <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> for the error location <span class="emphasis"><em>ignores</em></span>
  445. errors; it's equivalent to <code class="literal">try { <code class="function">sub_function_that_can_fail()</code>; } catch
  446. (...) {}</code> in C++. It does <span class="emphasis"><em>not</em></span> mean to leave errors
  447. unhandled; it means to handle them by doing nothing.
  448. </p>
  449. <p>
  450. Error domains and codes are conventionally named as follows:
  451. </p>
  452. <div class="itemizedlist"><ul class="itemizedlist" type="disc">
  453. <li class="listitem">
  454. <p>
  455. The error domain is called
  456. <code class="literal">&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR</code>, for example
  457. <a class="link" href="glib-Spawning-Processes.html#G-SPAWN-ERROR:CAPS" title="G_SPAWN_ERROR"><code class="literal">G_SPAWN_ERROR</code></a> or <a class="link" href="glib-Threads.html#G-THREAD-ERROR:CAPS" title="G_THREAD_ERROR"><code class="literal">G_THREAD_ERROR</code></a>:
  458. </p>
  459. <div class="informalexample">
  460. <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
  461. <tbody>
  462. <tr>
  463. <td class="listing_lines" align="right"><pre>1
  464. 2
  465. 3
  466. 4
  467. 5
  468. 6</pre></td>
  469. <td class="listing_code"><pre class="programlisting"><span class="preproc">#define</span><span class="normal"> </span><span class="usertype">G_SPAWN_ERROR</span><span class="normal"> </span><span class="function">g_spawn_error_quark</span><span class="normal"> </span><span class="symbol">()</span>
  470. <span class="normal"><a href="glib-Quarks.html#GQuark">GQuark</a></span>
  471. <span class="function">g_spawn_error_quark</span><span class="normal"> </span><span class="symbol">(</span><span class="type">void</span><span class="symbol">)</span>
  472. <span class="cbracket">{</span>
  473. <span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="function"><a href="glib-Quarks.html#g-quark-from-static-string">g_quark_from_static_string</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"g-spawn-error-quark"</span><span class="symbol">);</span>
  474. <span class="cbracket">}</span></pre></td>
  475. </tr>
  476. </tbody>
  477. </table>
  478. </div>
  479. <p>
  480. </p>
  481. </li>
  482. <li class="listitem"><p>
  483. The quark function for the error domain is called <code class="literal">&lt;namespace&gt;_&lt;module&gt;_error_quark</code>, for example <code class="function">g_spawn_error_quark()</code> or %<code class="function">g_thread_error_quark()</code>.
  484. </p></li>
  485. <li class="listitem"><p>
  486. The error codes are in an enumeration called
  487. <code class="literal">&lt;Namespace&gt;&lt;Module&gt;Error</code>; for example,
  488. <a class="link" href="glib-Threads.html#GThreadError" title="enum GThreadError"><span class="type">GThreadError</span></a> or <a class="link" href="glib-Spawning-Processes.html#GSpawnError" title="enum GSpawnError"><span class="type">GSpawnError</span></a>.
  489. </p></li>
  490. <li class="listitem"><p>
  491. Members of the error code enumeration are called <code class="literal">&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_&lt;CODE&gt;</code>, for example <a class="link" href="glib-Spawning-Processes.html#G-SPAWN-ERROR-FORK:CAPS"><code class="literal">G_SPAWN_ERROR_FORK</code></a> or <a class="link" href="glib-Threads.html#G-THREAD-ERROR-AGAIN:CAPS"><code class="literal">G_THREAD_ERROR_AGAIN</code></a>.
  492. </p></li>
  493. <li class="listitem"><p>
  494. If there's a "generic" or "unknown" error code for unrecoverable errors it
  495. doesn't make sense to distinguish with specific codes, it should be called
  496. <code class="literal">&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_FAILED</code>, for
  497. example <a class="link" href="glib-Spawning-Processes.html#G-SPAWN-ERROR-FAILED:CAPS"><code class="literal">G_SPAWN_ERROR_FAILED</code></a> or <code class="literal">G_THREAD_ERROR_FAILED</code>.
  498. </p></li>
  499. </ul></div>
  500. <p>
  501. </p>
  502. <p>
  503. Summary of rules for use of <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>:
  504. </p>
  505. <div class="itemizedlist"><ul class="itemizedlist" type="disc">
  506. <li class="listitem"><p>
  507. Do not report programming errors via <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>.
  508. </p></li>
  509. <li class="listitem"><p>
  510. The last argument of a function that returns an error should be a
  511. location where a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> can be placed (i.e. "<a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>** error"). If
  512. <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> is used with varargs, the <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>** should be the last
  513. argument before the "...".
  514. </p></li>
  515. <li class="listitem"><p>
  516. The caller may pass <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> for the <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>** if they are not interested
  517. in details of the exact error that occurred.
  518. </p></li>
  519. <li class="listitem"><p>
  520. If <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is passed for the <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>** argument, then errors should
  521. not be returned to the caller, but your function should still
  522. abort and return if an error occurs. That is, control flow should
  523. not be affected by whether the caller wants to get a <a class="link" href="glib-Error-Reporting.html#GEr…

Large files files are truncated, but you can click here to view the full file