00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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