unexpected revision 9bff67898d55cddfcec9ce30cc2b1bb6211ec691
2N/ACopyright (C) 1999, 2000 Internet Software Consortium.
2N/ASee COPYRIGHT in the source root or http://www.isc.org/copyright for terms.
2N/A
2N/AUnexpected Errors
2N/A
2N/AFor portability, the ISC and DNS libraries define their own result codes
2N/Ainstead of using the operating system's. E.g. the ISC library uses
2N/AISC_R_NOMEMORY instead of the UNIX-specific ENOMEM.
2N/A
2N/AThe ISC and DNS libraries have a common way of looking at errors and
2N/Aother non-success results. An "expected" result is something that can
2N/Ahappen in the ordinary course of using a function, that is not very
2N/Aimprobable, and that the caller might care to know. For example, a
2N/Afunction which opens a file must have a way to say "file not found"
2N/Aand "permission denied".
2N/A
2N/AOther kinds of errors are "unexpected". For example, an I/O error
2N/Amight occur. When an unexpected error occurs, we want to be able to
2N/Alog the information, but we don't want to translate every
2N/Aoperating-system-specific error code into and ISC_R_ or DNS_R_ code
2N/Abecause the are too many of them, and they aren't meaningful to
2N/Aclients anyway (they're unexpected errors). If we were using a
2N/Alanguage where we could throw an exception, we'd do that. Since we're
2N/Anot, we call UNEXPECTED_ERROR(). E.g.
2N/A
2N/A#include <isc/error.h>
2N/A
2N/Avoid foo() {
2N/A if (some_unix_thang() < 0) {
2N/A UNEXPECTED_ERROR(__FILE__, __LINE__,
2N/A "some_unix_thang() failed: %s",
2N/A strerror(errno));
2N/A return (ISC_R_UNEXPECTED);
2N/A }
2N/A}
2N/A
2N/AThe UNEXPECTED error routine may be specified by the calling application. It
2N/Awill log the error somehow (e.g. via. syslog, or printing to stderr).
2N/A
2N/AThis method is a compromise. It makes useful error information available,
2N/Abut avoids the complexity of a more sophisticated multi-library "error table"
2N/Ascheme.
2N/A
2N/AIn the (rare) situation where a library routine encounters a fatal error and
2N/Ahas no way of reporting the error to the application, the library may call
2N/AFATAL_ERROR(). This will log the problem and then terminate the application.
2N/A