conexus logo

except.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the conexus library.                             *
00006  *                                                                         *
00007  *   The conexus library is free software; you can redistribute it and/or  *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The conexus library is distributed in the hope that it will be        *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef CONEXUSEXCEPT_H
00020 #define CONEXUSEXCEPT_H
00021 
00026 #include <stdexcept>
00027 #include <errno.h>
00028 #include <sstream>
00029 
00030 namespace Conexus
00031 {
00032 
00038   class conexus_exception: public std::runtime_error
00039   {
00040     public:
00041       conexus_exception ( const std::string& s="Unknown exception.", int e=0, const std::string& c="" ) :
00042           std::runtime_error ( s ),
00043           m_exception_number ( e ),
00044           m_exception_string ( s ),
00045           m_class ( c )
00046       {
00047         if ( m_exception_number == 0 )
00048           m_exception_number = errno;
00049         std::ostringstream ostr;
00050         ostr << "conexus:" << m_class << ":";
00051         if ( m_exception_number != 0 )
00052           ostr << "errno[" << m_exception_number << "]: ";
00053         else
00054           ostr << " ";
00055         ostr << m_exception_string;
00056         m_return_string = ostr.str();
00057       }
00058 
00059       ~conexus_exception() throw () { }
00060 
00061       virtual const char * what () const throw ()
00062       {
00063         return m_return_string.c_str();
00064       }
00065 
00066     protected:
00067       int m_exception_number;
00068       std::string m_return_string;
00069       std::string m_exception_string;
00070       std::string m_class;
00071   };
00072 
00073 }
00074 
00075 #include <conexus/except_address.h>
00076 #include <conexus/except_bind.h>
00077 #include <conexus/except_close.h>
00078 #include <conexus/except_connect.h>
00079 #include <conexus/except_listen.h>
00080 #include <conexus/except_open.h>
00081 #include <conexus/except_read.h>
00082 #include <conexus/except_socket.h>
00083 #include <conexus/except_state.h>
00084 #include <conexus/except_write.h>
00085 
00086 namespace Conexus
00087 {
00088 
00089   typedef enum ExceptionType
00090   {
00091     EXCEPTION_ADDRESS,
00092     EXCEPTION_OPEN,
00093     EXCEPTION_BIND,
00094     EXCEPTION_CLOSE,
00095     EXCEPTION_CONNECT,
00096     EXCEPTION_LISTEN,
00097     EXCEPTION_READ,
00098     EXCEPTION_SOCKET,
00099     EXCEPTION_STATE,
00100     EXCEPTION_WRITE,
00101   } ExceptionType;
00102 
00103   void throw_exception ( int exception_num, ExceptionType type ) throw ( conexus_exception );
00104 
00105   void throw_bind_exception ( int exception_num ) throw ( bind_exception );
00106   void throw_close_exception ( int exception_num ) throw ( close_exception );
00107   void throw_connect_exception ( int exception_num ) throw ( connect_exception );
00108   void throw_listen_exception ( int exception_num ) throw ( listen_exception );
00109   void throw_open_exception ( int exception_num ) throw ( open_exception );
00110   void throw_read_exception ( int exception_num ) throw ( read_exception );
00111   void throw_write_exception ( int exception_num ) throw ( write_exception );
00112   void throw_address_exception ( int exception_num ) throw ( address_exception );
00113   void throw_socket_exception ( int exception_num ) throw ( socket_exception );
00114 
00120   class interface_index_exception: public conexus_exception
00121   {
00122     public:
00123       interface_index_exception() : conexus_exception ( "Interface index error; name or number does not exist" ) { }
00124   };
00125 
00126 
00127 
00128 } // namespace Conexus
00129 
00130 #endif
00131 

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8