00001 // more/errno.h -- a C++ally correct errno
00002 // Copyright (C) 2001 Petter Urkedal (petter.urkedal@matfys.lth.se)
00003 //
00004 // This file is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 2 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This file is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction. Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License. This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 //
00028 // $Id: errno.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00029
00030
00031 #ifndef MORE_DIAG_ERRNO_H
00032 #define MORE_DIAG_ERRNO_H
00033
00034 #include <stdexcept>
00035
00036 namespace more {
00037 namespace diag {
00038
00039 /** Return the value of errno. */
00040 int the_errno();
00041
00042 /** Equivalent to strerror(the_errno()). */
00043 char const* strerror();
00044 /** Equivalent to std::strerror(err). */
00045 char const* strerror(int err);
00046
00047 /** An exception used to report an errno condition. */
00048 struct errno_exception : std::runtime_error
00049 {
00050 /** An exception with the last errno condition. The base class
00051 is constructed with the corresponding strerror string. */
00052 errno_exception();
00053
00054 /** Same as errno_exception(), except adds a prefix and a
00055 separator ": " to the message. */
00056 explicit errno_exception(std::string);
00057
00058 /** An exception with a given errno condition. The base class is
00059 constructed with the corresponding strerror string. */
00060 explicit errno_exception(int);
00061
00062 /** Same as errno_exception(int), except adds a prefix and a
00063 separator ": " to the message. */
00064 explicit errno_exception(int, std::string);
00065
00066 /** Return the errno of this exception. */
00067 int the_errno() const { return n; }
00068
00069 private:
00070 int n;
00071 };
00072
00073 }} // more::diag
00074
00075 #endif