59
<refsect1 role="desc">
51
<refsect1 id="glib-Warnings-and-Assertions.description" role="desc">
60
52
<title role="desc.title">Description</title>
62
54
These functions provide support for outputting messages.
65
The <function>g_return</function> family of macros (<link linkend="g-return-if-fail"><function>g_return_if_fail()</function></link>,
57
The <function>g_return</function> family of macros (<link linkend="g-return-if-fail"><function>g_return_if_fail()</function></link>,
66
58
<link linkend="g-return-val-if-fail"><function>g_return_val_if_fail()</function></link>, <link linkend="g-return-if-reached"><function>g_return_if_reached()</function></link>, <link linkend="g-return-val-if-reached"><function>g_return_val_if_reached()</function></link>)
67
59
should only be used for programming errors, a typical use case is
68
60
checking for invalid parameters at the beginning of a public function.
69
61
They should not be used if you just mean "if (error) return", they
70
62
should only be used if you mean "if (bug in program) return".
71
The program behavior is generally considered undefined after one of these
63
The program behavior is generally considered undefined after one of these
72
64
checks fails. They are not intended for normal control flow, only to
73
give a perhaps-helpful warning before giving up.
65
give a perhaps-helpful warning before giving up.
77
<refsect1 role="details">
69
<refsect1 id="glib-Warnings-and-Assertions.details" role="details">
78
70
<title role="details.title">Details</title>
80
<title><anchor id="g-print" role="function"/>g_print ()</title>
81
<indexterm><primary>g_print</primary></indexterm><programlisting><link linkend="void">void</link> g_print (const <link linkend="gchar">gchar</link> *format,
71
<refsect2 id="g-print" role="function">
72
<title>g_print ()</title>
73
<indexterm zone="g-print"><primary sortas="g_print">g_print</primary></indexterm><programlisting><link linkend="void">void</link> g_print (const <link linkend="gchar">gchar</link> *format,
82
74
...);</programlisting>
84
76
Outputs a formatted message via the print handler.
110
100
By providing your own handler you can redirect the output, to a GTK+
111
101
widget or a log file for example.
112
102
</para><variablelist role="params">
113
<varlistentry><term><parameter>func</parameter> :</term>
103
<varlistentry><term><parameter>func</parameter> :</term>
114
104
<listitem><simpara>the new print handler.
115
105
</simpara></listitem></varlistentry>
116
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the old print handler.
106
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the old print handler.
119
107
</simpara></listitem></varlistentry>
120
108
</variablelist></refsect2>
122
<title><anchor id="GPrintFunc" role="function"/>GPrintFunc ()</title>
123
<indexterm><primary>GPrintFunc</primary></indexterm><programlisting><link linkend="void">void</link> (*GPrintFunc) (const <link linkend="gchar">gchar</link> *string);</programlisting>
109
<refsect2 id="GPrintFunc" role="function">
110
<title>GPrintFunc ()</title>
111
<indexterm zone="GPrintFunc"><primary sortas="GPrintFunc">GPrintFunc</primary></indexterm><programlisting><link linkend="void">void</link> (*GPrintFunc) (const <link linkend="gchar">gchar</link> *string);</programlisting>
125
113
Specifies the type of the print handler functions.
126
114
These are called with the complete formatted string to output.
127
115
</para><variablelist role="params">
128
<varlistentry><term><parameter>string</parameter> :</term>
116
<varlistentry><term><parameter>string</parameter> :</term>
129
117
<listitem><simpara>the message to be output.
132
118
</simpara></listitem></varlistentry>
133
119
</variablelist></refsect2>
135
<title><anchor id="g-printerr" role="function"/>g_printerr ()</title>
136
<indexterm><primary>g_printerr</primary></indexterm><programlisting><link linkend="void">void</link> g_printerr (const <link linkend="gchar">gchar</link> *format,
120
<refsect2 id="g-printerr" role="function">
121
<title>g_printerr ()</title>
122
<indexterm zone="g-printerr"><primary sortas="g_printerr">g_printerr</primary></indexterm><programlisting><link linkend="void">void</link> g_printerr (const <link linkend="gchar">gchar</link> *format,
137
123
...);</programlisting>
139
125
Outputs a formatted message via the error message handler.
143
129
<link linkend="g-printerr"><function>g_printerr()</function></link> should not be used from within libraries. Instead <link linkend="g-log"><function>g_log()</function></link> should
144
130
be used, or the convenience functions <link linkend="g-message"><function>g_message()</function></link>, <link linkend="g-warning"><function>g_warning()</function></link> and <link linkend="g-error"><function>g_error()</function></link>.
145
131
</para><variablelist role="params">
146
<varlistentry><term><parameter>format</parameter> :</term>
132
<varlistentry><term><parameter>format</parameter> :</term>
147
133
<listitem><simpara>the message format. See the <link linkend="printf"><function>printf()</function></link> documentation.
148
134
</simpara></listitem></varlistentry>
149
<varlistentry><term><parameter>...</parameter> :</term>
135
<varlistentry><term><parameter>...</parameter> :</term>
150
136
<listitem><simpara>the parameters to insert into the format string.
153
137
</simpara></listitem></varlistentry>
154
138
</variablelist></refsect2>
156
<title><anchor id="g-set-printerr-handler" role="function"/>g_set_printerr_handler ()</title>
157
<indexterm><primary>g_set_printerr_handler</primary></indexterm><programlisting><link linkend="GPrintFunc">GPrintFunc</link> g_set_printerr_handler (<link linkend="GPrintFunc">GPrintFunc</link> func);</programlisting>
139
<refsect2 id="g-set-printerr-handler" role="function">
140
<title>g_set_printerr_handler ()</title>
141
<indexterm zone="g-set-printerr-handler"><primary sortas="g_set_printerr_handler">g_set_printerr_handler</primary></indexterm><programlisting><link linkend="GPrintFunc">GPrintFunc</link> g_set_printerr_handler (<link linkend="GPrintFunc">GPrintFunc</link> func);</programlisting>
159
143
Sets the handler for printing error messages.
160
144
Any messages passed to <link linkend="g-printerr"><function>g_printerr()</function></link> will be output via the new handler.
162
146
By providing your own handler you can redirect the output, to a GTK+
163
147
widget or a log file for example.
164
148
</para><variablelist role="params">
165
<varlistentry><term><parameter>func</parameter> :</term>
149
<varlistentry><term><parameter>func</parameter> :</term>
166
150
<listitem><simpara>the new error message handler.
167
151
</simpara></listitem></varlistentry>
168
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the old error message handler.
152
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the old error message handler.
171
153
</simpara></listitem></varlistentry>
172
154
</variablelist></refsect2>
174
<title><anchor id="g-return-if-fail" role="macro"/>g_return_if_fail()</title>
175
<indexterm><primary>g_return_if_fail</primary></indexterm><programlisting>#define g_return_if_fail(expr)</programlisting>
155
<refsect2 id="g-return-if-fail" role="macro">
156
<title>g_return_if_fail()</title>
157
<indexterm zone="g-return-if-fail"><primary sortas="g_return_if_fail">g_return_if_fail</primary></indexterm><programlisting>#define g_return_if_fail(expr)</programlisting>
177
159
Returns from the current function if the expression is not true.
178
If the expression evaluates to <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>, a critical message is logged and
160
If the expression evaluates to <link linkend="FALSE--CAPS"><literal>FALSE</literal></link>, a critical message is logged and
179
161
the function returns. This can only be used in functions which do not return
181
163
</para><variablelist role="params">
182
<varlistentry><term><parameter>expr</parameter> :</term>
164
<varlistentry><term><parameter>expr</parameter> :</term>
183
165
<listitem><simpara>the expression to check.
186
166
</simpara></listitem></varlistentry>
187
167
</variablelist></refsect2>
189
<title><anchor id="g-return-val-if-fail" role="macro"/>g_return_val_if_fail()</title>
190
<indexterm><primary>g_return_val_if_fail</primary></indexterm><programlisting>#define g_return_val_if_fail(expr,val)</programlisting>
168
<refsect2 id="g-return-val-if-fail" role="macro">
169
<title>g_return_val_if_fail()</title>
170
<indexterm zone="g-return-val-if-fail"><primary sortas="g_return_val_if_fail">g_return_val_if_fail</primary></indexterm><programlisting>#define g_return_val_if_fail(expr,val)</programlisting>
192
172
Returns from the current function, returning the value <parameter>val</parameter>, if the expression
194
If the expression evaluates to <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>, a critical message is logged and
174
If the expression evaluates to <link linkend="FALSE--CAPS"><literal>FALSE</literal></link>, a critical message is logged and
195
175
<parameter>val</parameter> is returned.
196
176
</para><variablelist role="params">
197
<varlistentry><term><parameter>expr</parameter> :</term>
177
<varlistentry><term><parameter>expr</parameter> :</term>
198
178
<listitem><simpara>the expression to check.
199
179
</simpara></listitem></varlistentry>
200
<varlistentry><term><parameter>val</parameter> :</term>
180
<varlistentry><term><parameter>val</parameter> :</term>
201
181
<listitem><simpara>the value to return from the current function if the expression is not
205
183
</simpara></listitem></varlistentry>
206
184
</variablelist></refsect2>
208
<title><anchor id="g-return-if-reached" role="macro"/>g_return_if_reached()</title>
209
<indexterm><primary>g_return_if_reached</primary></indexterm><programlisting>#define g_return_if_reached()</programlisting>
185
<refsect2 id="g-return-if-reached" role="macro">
186
<title>g_return_if_reached()</title>
187
<indexterm zone="g-return-if-reached"><primary sortas="g_return_if_reached">g_return_if_reached</primary></indexterm><programlisting>#define g_return_if_reached()</programlisting>
211
Logs a critical message and returns from the current function.
189
Logs a critical message and returns from the current function.
212
190
This can only be used in functions which do not return a value.
213
191
</para></refsect2>
215
<title><anchor id="g-return-val-if-reached" role="macro"/>g_return_val_if_reached()</title>
216
<indexterm><primary>g_return_val_if_reached</primary></indexterm><programlisting>#define g_return_val_if_reached(val)</programlisting>
192
<refsect2 id="g-return-val-if-reached" role="macro">
193
<title>g_return_val_if_reached()</title>
194
<indexterm zone="g-return-val-if-reached"><primary sortas="g_return_val_if_reached">g_return_val_if_reached</primary></indexterm><programlisting>#define g_return_val_if_reached(val)</programlisting>
218
Logs a critical message and returns <parameter>val</parameter>.
196
Logs a critical message and returns <parameter>val</parameter>.
219
197
</para><variablelist role="params">
220
<varlistentry><term><parameter>val</parameter> :</term>
198
<varlistentry><term><parameter>val</parameter> :</term>
221
199
<listitem><simpara>the value to return from the current function.
224
</simpara></listitem></varlistentry>
225
</variablelist></refsect2>
227
<title><anchor id="g-warn-if-fail" role="macro"/>g_warn_if_fail()</title>
228
<indexterm><primary>g_warn_if_fail</primary></indexterm><programlisting>#define g_warn_if_fail(expr)</programlisting>
231
</para><variablelist role="params">
232
<varlistentry><term><parameter>expr</parameter> :</term>
236
</simpara></listitem></varlistentry>
237
</variablelist></refsect2>
239
<title><anchor id="g-warn-if-reached" role="macro"/>g_warn_if_reached()</title>
240
<indexterm><primary>g_warn_if_reached</primary></indexterm><programlisting>#define g_warn_if_reached()</programlisting>
245
<title><anchor id="g-warn-message" role="function"/>g_warn_message ()</title>
246
<indexterm><primary>g_warn_message</primary></indexterm><programlisting><link linkend="void">void</link> g_warn_message (const <link linkend="char">char</link> *domain,
247
const <link linkend="char">char</link> *file,
248
<link linkend="int">int</link> line,
249
const <link linkend="char">char</link> *func,
250
const <link linkend="char">char</link> *warnexpr);</programlisting>
253
</para><variablelist role="params">
254
<varlistentry><term><parameter>domain</parameter> :</term>
256
</simpara></listitem></varlistentry>
257
<varlistentry><term><parameter>file</parameter> :</term>
259
</simpara></listitem></varlistentry>
260
<varlistentry><term><parameter>line</parameter> :</term>
262
</simpara></listitem></varlistentry>
263
<varlistentry><term><parameter>func</parameter> :</term>
265
</simpara></listitem></varlistentry>
266
<varlistentry><term><parameter>warnexpr</parameter> :</term>
270
</simpara></listitem></varlistentry>
271
</variablelist></refsect2>
273
<title><anchor id="g-on-error-query" role="function"/>g_on_error_query ()</title>
274
<indexterm><primary>g_on_error_query</primary></indexterm><programlisting><link linkend="void">void</link> g_on_error_query (const <link linkend="gchar">gchar</link> *prg_name);</programlisting>
200
</simpara></listitem></varlistentry>
201
</variablelist></refsect2>
202
<refsect2 id="g-warn-if-fail" role="macro" condition="since:2.16">
203
<title>g_warn_if_fail()</title>
204
<indexterm zone="g-warn-if-fail" role="2.16"><primary sortas="g_warn_if_fail">g_warn_if_fail</primary></indexterm><programlisting>#define g_warn_if_fail(expr)</programlisting>
206
Logs a warning if the expression is not true.
207
</para><variablelist role="params">
208
<varlistentry><term><parameter>expr</parameter> :</term>
209
<listitem><simpara>the expression to check
210
</simpara></listitem></varlistentry>
211
</variablelist><para role="since">Since 2.16</para></refsect2>
212
<refsect2 id="g-warn-if-reached" role="macro" condition="since:2.16">
213
<title>g_warn_if_reached()</title>
214
<indexterm zone="g-warn-if-reached" role="2.16"><primary sortas="g_warn_if_reached">g_warn_if_reached</primary></indexterm><programlisting>#define g_warn_if_reached()</programlisting>
216
Logs a critical warning.
217
</para><para role="since">Since 2.16</para></refsect2>
218
<refsect2 id="g-on-error-query" role="function">
219
<title>g_on_error_query ()</title>
220
<indexterm zone="g-on-error-query"><primary sortas="g_on_error_query">g_on_error_query</primary></indexterm><programlisting><link linkend="void">void</link> g_on_error_query (const <link linkend="gchar">gchar</link> *prg_name);</programlisting>
276
222
Prompts the user with <computeroutput>[E]xit, [H]alt, show [S]tack trace or [P]roceed</computeroutput>.
277
223
This function is intended to be used for debugging use only. The following
323
265
This function may cause different actions on non-UNIX platforms.
324
266
</para><variablelist role="params">
325
<varlistentry><term><parameter>prg_name</parameter> :</term>
267
<varlistentry><term><parameter>prg_name</parameter> :</term>
326
268
<listitem><simpara>the program name, needed by <command>gdb</command> for the [S]tack trace option.
327
If <parameter>prg_name</parameter> is <link linkend="NULL:CAPS"><literal>NULL</literal></link>, <link linkend="g-get-prgname"><function>g_get_prgname()</function></link> is called to get the program name
269
If <parameter>prg_name</parameter> is <link linkend="NULL--CAPS"><literal>NULL</literal></link>, <link linkend="g-get-prgname"><function>g_get_prgname()</function></link> is called to get the program name
328
270
(which will work correctly if <link linkend="gdk-init"><function>gdk_init()</function></link> or <link linkend="gtk-init"><function>gtk_init()</function></link> has been called).
331
271
</simpara></listitem></varlistentry>
332
272
</variablelist></refsect2>
334
<title><anchor id="g-on-error-stack-trace" role="function"/>g_on_error_stack_trace ()</title>
335
<indexterm><primary>g_on_error_stack_trace</primary></indexterm><programlisting><link linkend="void">void</link> g_on_error_stack_trace (const <link linkend="gchar">gchar</link> *prg_name);</programlisting>
273
<refsect2 id="g-on-error-stack-trace" role="function">
274
<title>g_on_error_stack_trace ()</title>
275
<indexterm zone="g-on-error-stack-trace"><primary sortas="g_on_error_stack_trace">g_on_error_stack_trace</primary></indexterm><programlisting><link linkend="void">void</link> g_on_error_stack_trace (const <link linkend="gchar">gchar</link> *prg_name);</programlisting>
337
277
Invokes <command>gdb</command>, which attaches to the current process and shows a stack trace.
338
278
Called by <link linkend="g-on-error-query"><function>g_on_error_query()</function></link> when the [S]tack trace option is selected.
341
281
This function may cause different actions on non-UNIX platforms.
342
282
</para><variablelist role="params">
343
<varlistentry><term><parameter>prg_name</parameter> :</term>
283
<varlistentry><term><parameter>prg_name</parameter> :</term>
344
284
<listitem><simpara>the program name, needed by <command>gdb</command> for the [S]tack trace option.
345
If <parameter>prg_name</parameter> is <link linkend="NULL:CAPS"><literal>NULL</literal></link>, <link linkend="g-get-prgname"><function>g_get_prgname()</function></link> is called to get the program name
285
If <parameter>prg_name</parameter> is <link linkend="NULL--CAPS"><literal>NULL</literal></link>, <link linkend="g-get-prgname"><function>g_get_prgname()</function></link> is called to get the program name
346
286
(which will work correctly if <link linkend="gdk-init"><function>gdk_init()</function></link> or <link linkend="gtk-init"><function>gtk_init()</function></link> has been called).
349
287
</simpara></listitem></varlistentry>
350
288
</variablelist></refsect2>
352
<title><anchor id="G-BREAKPOINT:CAPS" role="macro"/>G_BREAKPOINT()</title>
353
<indexterm><primary>G_BREAKPOINT</primary></indexterm><programlisting>#define G_BREAKPOINT()</programlisting>
289
<refsect2 id="G-BREAKPOINT--CAPS" role="macro">
290
<title>G_BREAKPOINT()</title>
291
<indexterm zone="G-BREAKPOINT--CAPS"><primary sortas="G_BREAKPOINT">G_BREAKPOINT</primary></indexterm><programlisting>#define G_BREAKPOINT()</programlisting>
355
293
Inserts a breakpoint instruction into the code. On x86 and alpha systems
356
294
this is implemented as a soft interrupt and on other architectures it raises
357
a <link linkend="SIGTRAP:CAPS"><literal>SIGTRAP</literal></link> signal.
295
a <link linkend="SIGTRAP--CAPS"><literal>SIGTRAP</literal></link> signal.
358
296
</para></refsect2>