Next Previous Contents

4. Error status (apr_status_t)

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:

/* pseudo code about apr_status_t check */
apr_status_t rv;
rv = apr_pool_create(&mp, NULL);
if (rv != APR_SUCCESS) {
   ERROR-HANDLING;
}

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.

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.

I recommend you to follow the simple rules.

One API that you had better know is apr_strerror(). You can show the error description as follows:

/* 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 */
}


Next Previous Contents