⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-warnings-and-assertions.html

📁 glid编写实例
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<p>Returns from the current function if the expression is not true.If the expression evaluates to <code class="literal">FALSE</code>, a critical message is logged andthe function returns. This can only be used in functions which do not returna value.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>expr</code></em>&#160;:</span></td><td>the expression to check.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930232"></a><h3><a name="g-return-val-if-fail"></a>g_return_val_if_fail()</h3><a class="indexterm" name="id2930242"></a><pre class="programlisting">#define     g_return_val_if_fail(expr,val)</pre><p>Returns from the current function, returning the value <em class="parameter"><code>val</code></em>, if the expressionis not true.If the expression evaluates to <code class="literal">FALSE</code>, a critical message is logged and<em class="parameter"><code>val</code></em> is returned.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>expr</code></em>&#160;:</span></td><td>the expression to check.</td></tr><tr><td><span class="term"><em class="parameter"><code>val</code></em>&#160;:</span></td><td>the value to return from the current function if the expression is nottrue.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930310"></a><h3><a name="g-return-if-reached"></a>g_return_if_reached()</h3><a class="indexterm" name="id2930321"></a><pre class="programlisting">#define     g_return_if_reached()</pre><p>Logs a critical message and returns from the current function. This can only be used in functions which do not return a value.</p></div><hr><div class="refsect2" lang="en"><a name="id2930339"></a><h3><a name="g-return-val-if-reached"></a>g_return_val_if_reached()</h3><a class="indexterm" name="id2930350"></a><pre class="programlisting">#define     g_return_val_if_reached(val)</pre><p>Logs a critical message and returns <em class="parameter"><code>val</code></em>. </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>val</code></em>&#160;:</span></td><td>the value to return from the current function.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930389"></a><h3><a name="g-assert"></a>g_assert()</h3><a class="indexterm" name="id2930400"></a><pre class="programlisting">#define     g_assert(expr)</pre><p>Debugging macro to terminate the application if the assertion fails.If the assertion fails (i.e. the expression is not true), an error messageis logged and the application is terminated.</p><p>The macro can be turned off in final releases of code by defining<span class="type">G_DISABLE_ASSERT</span> when compiling the application.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>expr</code></em>&#160;:</span></td><td>the expression to check.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930451"></a><h3><a name="g-assert-not-reached"></a>g_assert_not_reached()</h3><a class="indexterm" name="id2930462"></a><pre class="programlisting">#define     g_assert_not_reached()</pre><p>Debugging macro to terminate the application if it is ever reached.If it is reached, an error message is logged and the application is terminated.</p><p>The macro can be turned off in final releases of code by defining<span class="type">G_DISABLE_ASSERT</span> when compiling the application.</p></div><hr><div class="refsect2" lang="en"><a name="id2930494"></a><h3><a name="g-on-error-query"></a>g_on_error_query ()</h3><a class="indexterm" name="id2930505"></a><pre class="programlisting">void        g_on_error_query                (const <a href="glib-Basic-Types.html#gchar">gchar</a> *prg_name);</pre><p>Prompts the user with <code class="computeroutput">[E]xit, [H]alt, show [S]tack trace or [P]roceed</code>.This function is intended to be used for debugging use only. The followingexample shows how it can be used together with the <a href="glib-Message-Logging.html#g-log"><code class="function">g_log()</code></a> functions.</p><div class="informalexample"><pre class="programlisting">#include &lt;glib.h&gt;static void log_handler (const gchar   *log_domain,	     GLogLevelFlags log_level,	     const gchar   *message,	     gpointer       user_data){  g_log_default_handler (log_domain, log_level, message, user_data);  g_on_error_query (MY_PROGRAM_NAME);}int main (int argc, char *argv[]){  g_log_set_handler (MY_LOG_DOMAIN,		     G_LOG_LEVEL_WARNING |                      G_LOG_LEVEL_ERROR |                      G_LOG_LEVEL_CRITICAL,		     log_handler,		     NULL); /* ... */  </pre></div><p>If [E]xit is selected, the application terminates with a call to<code class="function">_exit(0)</code>.</p><p>If [H]alt is selected, the application enters an infinite loop.The infinite loop can only be stopped by killing the application,or by setting <span class="type">glib_on_error_halt</span> to <code class="literal">FALSE</code> (possibly via a debugger).</p><p>If [S]tack trace is selected, <a href="glib-Warnings-and-Assertions.html#g-on-error-stack-trace"><code class="function">g_on_error_stack_trace()</code></a> is called. Thisinvokes <span><strong class="command">gdb</strong></span>, which attaches to the current process and shows a stack trace.The prompt is then shown again.</p><p>If [P]roceed is selected, the function returns.</p><p>This function may cause different actions on non-UNIX platforms.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>prg_name</code></em>&#160;:</span></td><td>the program name, needed by <span><strong class="command">gdb</strong></span> for the [S]tack trace option.If <em class="parameter"><code>prg_name</code></em> is <code class="literal">NULL</code>, <a href="glib-Miscellaneous-Utility-Functions.html#g-get-prgname"><code class="function">g_get_prgname()</code></a> is called to get the program name(which will work correctly if <ahref="../gdk/gdk-General.html#gdk-init"><code class="function">gdk_init()</code></a> or <ahref="../gtk/gtk-General.html#gtk-init"><code class="function">gtk_init()</code></a> has been called).</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930713"></a><h3><a name="g-on-error-stack-trace"></a>g_on_error_stack_trace ()</h3><a class="indexterm" name="id2930724"></a><pre class="programlisting">void        g_on_error_stack_trace          (const <a href="glib-Basic-Types.html#gchar">gchar</a> *prg_name);</pre><p>Invokes <span><strong class="command">gdb</strong></span>, which attaches to the current process and shows a stack trace.Called by <a href="glib-Warnings-and-Assertions.html#g-on-error-query"><code class="function">g_on_error_query()</code></a> when the [S]tack trace option is selected.</p><p>This function may cause different actions on non-UNIX platforms.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>prg_name</code></em>&#160;:</span></td><td>the program name, needed by <span><strong class="command">gdb</strong></span> for the [S]tack trace option.If <em class="parameter"><code>prg_name</code></em> is <code class="literal">NULL</code>, <a href="glib-Miscellaneous-Utility-Functions.html#g-get-prgname"><code class="function">g_get_prgname()</code></a> is called to get the program name(which will work correctly if <ahref="../gdk/gdk-General.html#gdk-init"><code class="function">gdk_init()</code></a> or <ahref="../gtk/gtk-General.html#gtk-init"><code class="function">gtk_init()</code></a> has been called).</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930844"></a><h3><a name="G-BREAKPOINT:CAPS"></a>G_BREAKPOINT()</h3><a class="indexterm" name="id2930855"></a><pre class="programlisting">#define     G_BREAKPOINT()</pre><p>Inserts a breakpoint instruction into the code (on x86 machines only).</p></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Error-Reporting.html"><b>&lt;&lt;&#160;Error Reporting</b></a></td><td align="right"><a accesskey="n" href="glib-Message-Logging.html"><b>Message Logging&#160;&gt;&gt;</b></a></td></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -