ivd_SysError Class Reference
[Common, basic classes, functions and types]

#include <ivderror.h>

Inheritance diagram for ivd_SysError:

Inheritance graph
[legend]
Collaboration diagram for ivd_SysError:

Collaboration graph
[legend]

List of all members.


Detailed Description

system errors.

ivd_SysError exception is thrown, when a system error is detected in one of the lower level classes and can't be resolved. Resolving a situation is left to an upper level class (or member function), which most probably converts this kind of an exception to a ivd_Error exception.

Constructor takes latest a system error code that is then internally converted into text using the strerror function.

Example:

    void WriteLogHeader() {
        ivd_Stat_t info;
        int result = ivd_STAT( GetFileName().c_str(), &info );
        //
        // Check if a file exists or is empty:
        // Write header to a log file then.
        //
        if( result != 0) {
            if (errno == ENOENT) {
                writeHdr = true;
            }
            else {
                log_MARKLINE_m;
                throw ivd_SysError(
                    errno,
                    "Trying to get ivd_STAT of log file.",
                    true
                );
                // print an error
            }
        }
        else if (info.st_size == 0) {
            writeHdr = true;
        }
    }

    try {
        WriteLogHeader();
    }
    catch (ivd_SysError e) {
        switch (e.GetError()) {
           case 2:
                throw ivd_Error(ie_FILE_ACCESS, "Problems accessing log file");
                break;
        }
    }

Author:
Matej Kenda, Hermes SoftLab
See also:
ivd_Exception

ivd_Error

log_MARKLINE_m

Definition at line 175 of file ivderror.h.


Public Member Functions

 ivd_SysError (const int a_sysErr, const string &a_context="", bool a_logError=false) throw ()
 ivd_SysError (const int a_sysErr, const string &a_context, const string &a_detailed, bool a_logError=false) throw ()
virtual ~ivd_SysError () throw ()

Protected Member Functions

virtual string GetErrorText () const
 Overloaded function supplies a textual representation of error code, stored in ivd_Exception::m_error.

Private Attributes

 log_CLASSID_m

Constructor & Destructor Documentation

ivd_SysError::ivd_SysError ( const int  a_sysErr,
const string &  a_context = "",
bool  a_logError = false 
) throw ()

Definition at line 91 of file ivd_syserror.cpp.

References s_className.

00092     : ivd_Exception(a_sysErr, a_context, a_logError)  {
00093 
00094     FormatText(s_className);
00095 }

ivd_SysError::ivd_SysError ( const int  a_sysErr,
const string &  a_context,
const string &  a_detailed,
bool  a_logError = false 
) throw ()

Definition at line 97 of file ivd_syserror.cpp.

References s_className.

00101     : ivd_Exception(a_sysErr, a_context, a_detailed, a_logError)  {
00102 
00103     FormatText(s_className);
00104 }

ivd_SysError::~ivd_SysError (  )  throw () [virtual]

Definition at line 106 of file ivd_syserror.cpp.

00106                                     {
00107 }


Member Function Documentation

string ivd_SysError::GetErrorText (  )  const [protected, virtual]

Overloaded function supplies a textual representation of error code, stored in ivd_Exception::m_error.

Reimplemented from ivd_BaseException.

Definition at line 113 of file ivd_syserror.cpp.

References len, ivd_BaseException::m_error, and NULL.

00113                                         {
00114 
00115 #if TGT_OS_windows
00116     // Windows error codes
00117     LPVOID msgBuf;
00118     DWORD len;
00119 
00120     if ((len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00121                              FORMAT_MESSAGE_FROM_SYSTEM | 
00122                              FORMAT_MESSAGE_IGNORE_INSERTS,
00123                              NULL,
00124                              m_error,
00125                              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00126                              (LPTSTR) &msgBuf,
00127                              0,
00128                              NULL)) > 0) {
00129 
00130         char sysErrText[256];
00131         WideCharToMultiByte(CP_UTF8, 0, (LPTSTR) msgBuf, -1, 
00132                             sysErrText, 256, NULL, NULL);
00133         LocalFree(msgBuf);
00134 
00135         // remove from newline to the end of string
00136         char *pos;
00137         if ((pos = strchr(sysErrText, 13)) != NULL) {
00138             pos[0] = 0;
00139         }
00140         
00141         return string(sysErrText);
00142     }
00143     else {
00144         return string("Unknown error - no description.");
00145     }
00146 #else
00147     // POSIX error codes
00148     
00149     static const int c_len(255);
00150     char errorText[c_len];
00151 #if TGT_OS_hpux
00152     char* result = strerror(m_error);
00153 #elif TGT_OS_linux
00154     // Threadsafe strerror.
00155     char* result = strerror_r(m_error, errorText, c_len);
00156 #endif
00157 
00158     if (result == NULL) {
00159         ostringstream sstr;
00160         sstr << "Unknown system error: " << m_error;
00161         return sstr.str();
00162     }
00163     
00164     return string(result);
00165 #endif
00166 }


Member Data Documentation

Reimplemented from ivd_Exception.

Definition at line 196 of file ivderror.h.


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:41:57 2012 for OPENARCHIVE by  doxygen 1.5.6