SWBaseError()Methods:
Users should always use this constructor when creating a new class, eg. "SWBaseSocket::SWBaseError myError;".
SWBaseError(base_error e)
Used to convert from the base_error datatype.
virtual std::string get_error()
Get a human readable error string (empty if no error occurred).
virtual SWBaseSocket* get_failedClass(void)
Get a pointer to the class where the error occurred (or NULL if no error occurred).
virtual void set_errorString(std::string msg)
Set the error string. Should normally not be used.
virtual void set_failedClass(SWBaseSocket *pnt)
Set the failed class pointer. Should normally not be used.
virtual bool operator==(SWBaseError e)
virtual bool operator!=(SWBaseError e)
Allows you to compare this object with other errors. This is explained below.
...
SWInetSocket myInetSocket;
SWSSLSocket mySSLSocket;
SWBaseSocket::SWBaseError BError;
SWSSLSocket::SWSSLError SError;
...
myInetSocket.foo(&BError);
if( BError != SWBaseSocket::ok )
// ...
if( BError == SWSSLSocket::badPasswd ) // NOT OK! Can't compare with SWSSLSocket specific errors
// ...
...
myInetSocket.foo(&SError);
if( SError != SWBaseSocket::ok )
// ...
if( SError == SWSSLSocket::badPasswd ) // Ok, but SWInetSocket will never generate this error
// ...
...
mySSLSocket.bar(&BError);
if( BError != SWBaseSocket::ok )
// ...
if( BError == SWSSLSocket::badPasswd ) // STILL NOT OK! SWSSLSocket can generate this error
// ... // but SWBaseError can not represent it. BError will
... // indicate SWBaseSocket::fatal instead.
mySSLSocket.bar(&SError);
if( SError != SWBaseSocket::ok )
// ...
if( SError == SWSSLSocket::badPasswd ) // Ok, badPasswd is a possible error
// ...
|
sw_setThrowMode(true);
sw_setVerboseMode(false);
SWInetSocket myInetSocket;
SWSSLSocket mySSLSocket;
...
try{
myInetSocket.foo();
mySSLSocket.bar();
}
catch( SWSSLSocket::SWSSLError &error ){
// Will catch all exceptions from SWSSLSocket
// and derived classes that have a SSL specific
// error type
if( error == SWSSLSocket::badPasswd )
...
}
catch( SWBaseSocket::SWBaseError &error ){
// Will catch all exceptions from SWBaseSocket
// and derived classes
if( error == SWBaseSocket::terminated )
...
}
|
Copyright © 2003 Anders Lindström
Last updated 031023