debian/tmp/usr/include/conexus-0.5/conexus/except.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 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         return m_return_string.c_str();
00063       }
00064 
00065     protected:
00066       int m_exception_number;
00067       std::string m_return_string;
00068       std::string m_exception_string;
00069       std::string m_class;
00070     }
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_state.h>
00083 #include <conexus/except_write.h>
00084 
00085 namespace Conexus {
00086 
00087 typedef enum ExceptionType {
00088     EXCEPTION_OPEN,
00089     EXCEPTION_BIND,
00090     EXCEPTION_CLOSE,
00091     EXCEPTION_CONNECT,
00092     EXCEPTION_LISTEN,
00093     EXCEPTION_READ,
00094     EXCEPTION_STATE,
00095     EXCEPTION_WRITE,
00096     EXCEPTION_ADDRESS,
00097   } ExceptionType;
00098 
00099 void throw_exception(int exception_num, ExceptionType type) throw (conexus_exception);
00100 
00101 void throw_bind_exception(int exception_num) throw (bind_exception);
00102 void throw_close_exception(int exception_num) throw (close_exception);
00103 void throw_connect_exception(int exception_num) throw (connect_exception);
00104 void throw_listen_exception(int exception_num) throw (listen_exception);
00105 void throw_open_exception(int exception_num) throw (open_exception);
00106 void throw_read_exception(int exception_num) throw (read_exception);
00107 void throw_write_exception(int exception_num) throw (write_exception);
00108 void throw_address_exception(int exception_num) throw (address_exception);
00109 
00110 } // namespace Conexus
00111 
00112 #endif
00113 

Generated on Tue Mar 13 19:54:43 2007 by  doxygen 1.5.1