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