NetworkEx.cpp

Go to the documentation of this file.
00001 
00014 // NetworkEx.cpp -- implementation of NetworkException class
00015 
00016 #include "NetworkEx.h"
00017 
00018 
00020 // Quick and dirty way to do error resources.  The message_catalog
00021 // from the C++ standard should be used, but I can't find any information
00022 // on how it is used
00023 
00024 struct ErrorMap
00025 {
00026         const char* symbol;
00027         const char* description;
00028 }
00029 NetworkExceptions[] =
00030 {
00031         "invalid_address","An unknown or invalid address was supplied.",
00032         "invalid_host","Unknown or invalid host name was supplied.",
00033         "invalid_network","An invalid network name was supplied.",
00034         "invalid_service","An invalid service name was supplied.",
00035         "read_failed","A read operation failed.",
00036         "write_failed","A write operation failed.",
00037         "socket_path_exceeded","File path exceeded the system limit.",
00038         "eof_encountered","An end of file marker was detected while reading from a stream.",
00039         "system_call_failure","The operating system reported a failure during a system call.",
00040         "system_call_timout","The call made to the operating system has timed out."
00041 };
00042 
00043 
00045 // class NetworkException
00046 
00047 // Constructor.
00048 NetworkException::NetworkException(ExceptionCode code,const char* note,long native) : std::exception( ),
00049         exceptionCode( code ),nativeCode( native )
00050 {
00051 }
00052 
00053 // Return error value from enumeration
00054 NetworkException::ExceptionCode NetworkException::getErrorCode() const throw ()
00055 {
00056         return exceptionCode;
00057 }
00058 
00059 // Return the native operating system error code.
00060 
00061 long NetworkException::getNativeErrorCode() const throw ()
00062 {
00063         return nativeCode;
00064 }
00065 
00066 const char *NetworkException::what() const throw()
00067 {
00068     return getErrorDescription( getErrorCode() );
00069 }
00070 
00071 // Throws a network exception
00072 void NetworkException::throwNetworkException(ExceptionCode code, const char* message) //throw(NetworkException)
00073 {
00074         std::ostringstream stream;
00075         stream << code << ": " << message << std::ends;
00076         throw NetworkException( code,stream.str().c_str());
00077 }
00078 
00079 // Throws a network exception with the given native error
00080 void NetworkException::throwNetworkException(ExceptionCode code, long nativeError) //throw(NetworkException)
00081 {
00082         std::ostringstream stream;
00083         stream << getErrorSymbol(code) << ": " << "OS Error code is " << nativeError << std::ends;
00084         throw NetworkException(code,stream.str().c_str(),nativeError);
00085 }
00086 
00087 const char* NetworkException::getErrorSymbol( long code )
00088 {
00089         if (code < 0 ||code >= sizeof( NetworkExceptions ) / sizeof( ErrorMap ))
00090                 return 0;
00091 
00092         return NetworkExceptions[ code ].symbol;
00093 }
00094 
00095 const char* NetworkException::getErrorDescription( long code )
00096 {
00097         if (code < 0 || code >= sizeof( NetworkExceptions ) / sizeof( ErrorMap ))
00098                 return 0;
00099         return NetworkExceptions[ code ].description;
00100 }

Generated on Tue Mar 28 09:10:14 2006 for Simple SOAP by  doxygen 1.4.6