error.h

00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program 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 Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef CONEXUSERROR_H
00020 #define CONEXUSERROR_H
00021 
00026 #include <stdexcept>
00027 #include <errno.h>
00028 #include <sstream>
00029 
00030 namespace Conexus
00031   {
00032 
00038   class conexus_error: public std::runtime_error
00039     {
00040     public:
00041     conexus_error(const std::string s="Unknown error.", int e=0, const std::string c=""):
00042           std::runtime_error(s),
00043           m_error_number(e),
00044         m_error_string(s),
00045         m_class(c)
00046       {
00047         if (m_error_number == 0)
00048           m_error_number = errno;
00049         std::ostringstream ostr;
00050       ostr << "conexus:" << m_class << ":";
00051         if (m_error_number != 0)
00052           ostr << "errno[" << m_error_number << "]: ";
00053         else
00054           ostr << " ";
00055         ostr << m_error_string;
00056         m_return_string = ostr.str();
00057       }
00058 
00059       ~conexus_error() throw () { }
00060 
00061       virtual const char * what () const throw () {
00062         return m_return_string.c_str();
00063       }
00064 
00065     protected:
00066       int m_error_number;
00067       std::string m_return_string;
00068       std::string m_error_string;
00069       std::string m_class;
00070     }
00071   ;
00072 
00073   }
00074 
00075 #include <conexus/error_address.h>
00076 #include <conexus/error_bind.h>
00077 #include <conexus/error_close.h>
00078 #include <conexus/error_connect.h>
00079 #include <conexus/error_listen.h>
00080 #include <conexus/error_open.h>
00081 #include <conexus/error_read.h>
00082 #include <conexus/error_state.h>
00083 #include <conexus/error_write.h>
00084 
00085 namespace Conexus {
00086 
00087 typedef enum ErrorType {
00088     ERROR_OPEN,
00089     ERROR_BIND,
00090     ERROR_CLOSE,
00091     ERROR_CONNECT,
00092     ERROR_LISTEN,
00093     ERROR_READ,
00094     ERROR_STATE,
00095     ERROR_WRITE,
00096     ERROR_ADDRESS,
00097   } ErrorType;
00098 
00099 void throw_error(int error_num, ErrorType type) throw (conexus_error);
00100 
00101 void throw_bind_error(int error_num) throw (bind_error);
00102 void throw_close_error(int error_num) throw (close_error);
00103 void throw_connect_error(int error_num) throw (connect_error);
00104 void throw_listen_error(int error_num) throw (listen_error);
00105 void throw_open_error(int error_num) throw (open_error);
00106 void throw_read_error(int error_num) throw (read_error);
00107 void throw_write_error(int error_num) throw (write_error);
00108 void throw_address_error(int error_num) throw (address_error);
00109 
00110 } // namespace Conexus
00111 
00112 #endif
00113 

Generated on Sat Aug 26 17:34:53 2006 by  doxygen 1.4.6