Main Page | Namespace List | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

exceptions.h

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * $Id: exceptions.h,v 1.2 2005/05/25 18:58:46 cowo Exp $ 00003 ****************************************************************************/ 00004 /* 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00026 #ifndef _EXCEPTIONS_H_ 00027 #define _EXCEPTIONS_H_ 00028 #include <exception> 00029 #include <sstream> 00030 00031 using namespace std; 00032 00033 #define UsbEx(S) \ 00034 UsbException(__FILE__, __LINE__, usb_strerror (), S) 00035 #define YeppEx(S) \ 00036 YeppException(__FILE__, __LINE__, S) 00037 #define YeppEx_default() \ 00038 YeppException(__FILE__, __LINE__, last_error()) 00039 00041 class UsbException : public exception { 00042 public: 00043 UsbException(const char *file, int line, char *usb_strerror, const string& reason) throw() { 00044 _file = file; 00045 _line = line; 00046 _errorString = reason; 00047 _usberrorString = usb_strerror; 00048 }; 00049 UsbException(const char *file, int line, char *usb_strerror, const char *reason) throw() { 00050 _file = file; 00051 _line = line; 00052 _errorString = reason; 00053 _usberrorString = usb_strerror; 00054 }; 00055 UsbException (const UsbException& right) throw() { 00056 _file = right._file; 00057 _line = right._line; 00058 _errorString = right._errorString; 00059 _usberrorString = right._usberrorString; 00060 } 00061 virtual ~UsbException() throw() { }; 00062 virtual const char *what() const throw () { 00063 stringstream s(ios_base::in|ios_base::out); 00064 s << "libusb error (" << _file << ":" << _line; 00065 s << ") " << _errorString << ": " << _usberrorString; 00066 s.str(_errorString); 00067 return ( _errorString.c_str()); 00068 } 00069 private: 00070 string _errorString; 00071 string _usberrorString; 00072 string _file; 00073 int _line; 00074 }; 00075 00077 class YeppException : public exception { 00078 public: 00079 YeppException(const char *file, int line, const string& reason) throw() { 00080 _file = file; 00081 _line = line; 00082 _errorString = reason; 00083 }; 00084 YeppException(const YeppException& right) throw() { 00085 _file = right._file; 00086 _line = right._line; 00087 _errorString = right._errorString; 00088 }; 00089 virtual ~YeppException() throw() { }; 00090 virtual const char *what() const throw () { 00091 stringstream s(ios_base::in|ios_base::out); 00092 s << "Yepp error (" << _file << ":" << _line; 00093 s << ") " << _errorString; 00094 s.str(_errorString); 00095 return ( _errorString.c_str()); 00096 } 00097 private: 00098 string _errorString; 00099 string _file; 00100 int _line; 00101 }; 00102 00103 #endif

Generated on Sun May 29 16:13:38 2005 for yex by doxygen 1.3.7