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

📄 apr-tutorial-4.html

📁 跨平台windowsunixlinux的c语言编程解决方案
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.21"> <TITLE>libapr(apache portable runtime) programming tutorial: Error status (apr_status_t)</TITLE> <LINK HREF="apr-tutorial-5.html" REL=next> <LINK HREF="apr-tutorial-3.html" REL=previous> <LINK HREF="apr-tutorial.html#toc4" REL=contents></HEAD><BODY><A HREF="apr-tutorial-5.html">Next</A><A HREF="apr-tutorial-3.html">Previous</A><A HREF="apr-tutorial.html#toc4">Contents</A><HR><H2><A NAME="s4">4.</A> <A HREF="apr-tutorial.html#toc4">Error status (apr_status_t)</A></H2><P>Most of libapr functions return apr_status_t value. apr_status_t value is each of APR_SUCCESS or the others. APR_SUCCESS just indicates success. A typical code looks as follows:</P><P><BLOCKQUOTE><CODE><PRE>/* pseudo code about apr_status_t check */apr_status_t rv;rv = apr_pool_create(&amp;mp, NULL);if (rv != APR_SUCCESS) {   ERROR-HANDLING;}</PRE></CODE></BLOCKQUOTE></P><P>libapr defines some error statuses such as APR_EINVAL, and some error-check macros such as APR_STATUS_IS_ENOMEM((). Some of them are rather useful on handling portability issues. A typical one is APR_STATUS_IS_EAGAIN() macro. Historically, there are two error numbers that have the same meaning, EAGAIN and EWOULDBLOCK. APR_STATUS_IS_EAGAIN() macro takes care of the issue. </P><P>Nevertheless, it is almost impossible to deal with all error cases independently from many OSes. libapr doesn't reinvent the wheel on error handling. All libapr does is very simple.</P><P><UL><LI>In success, return APR_SUCCESS</LI><LI>In libapr layer's error, return APR_FOO error code</LI><LI>In very common OS error, return APR_FOO error code</LI><LI>In most of OS dependent error, return OS error number with the offset</LI></UL></P><P>I recommend you to follow the simple rules.</P><P><UL><LI>To compare return value with APR_SUCCESS</LI><LI>If you need to know more error details, to compare the values with the other error code</LI></UL></P><P>One API that you had better know is apr_strerror(). You can show the error description as follows:</P><P><BLOCKQUOTE><CODE><PRE>/* pseudo code about apr_strerror() */apr_status_t rv;rv = apr_foo_bar();if (rv != APR_SUCCESS) {   char errbuf[256];   apr_strerror(rv, buf, sizeof(buf));   puts(errbuf);  /* show the error description */}</PRE></CODE></BLOCKQUOTE></P><HR><A HREF="apr-tutorial-5.html">Next</A><A HREF="apr-tutorial-3.html">Previous</A><A HREF="apr-tutorial.html#toc4">Contents</A></BODY></HTML>

⌨️ 快捷键说明

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