Public Member Functions | Protected Member Functions | Private Attributes

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

system errors. More...

#include <ivderror.h>

Inheritance diagram for ivd_SysError:
Inheritance graph
[legend]
Collaboration diagram for ivd_SysError:
Collaboration graph
[legend]

List of all members.

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

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 190 of file ivderror.h.


Constructor & Destructor Documentation

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

Definition at line 105 of file ivd_syserror.cpp.

References s_className.

    : ivd_Exception(a_sysErr, a_context, a_logError)  {

    FormatText(s_className);
}

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

Definition at line 111 of file ivd_syserror.cpp.

References s_className.

    : ivd_Exception(a_sysErr, a_context, a_detailed, a_logError)  {

    FormatText(s_className);
}

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

Definition at line 120 of file ivd_syserror.cpp.

                                    {
}


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 127 of file ivd_syserror.cpp.

References len, ivd_BaseException::m_error, and NULL.

                                        {

#if TGT_OS_windows
    // Windows error codes
    LPVOID msgBuf;
    DWORD len;

    if ((len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                             FORMAT_MESSAGE_FROM_SYSTEM | 
                             FORMAT_MESSAGE_IGNORE_INSERTS,
                             NULL,
                             m_error,
                             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                             (LPTSTR) &msgBuf,
                             0,
                             NULL)) > 0) {

        char sysErrText[256];
        WideCharToMultiByte(CP_UTF8, 0, (LPTSTR) msgBuf, -1, 
                            sysErrText, 256, NULL, NULL);
        LocalFree(msgBuf);

        // remove from newline to the end of string
        char *pos;
        if ((pos = strchr(sysErrText, 13)) != NULL) {
            pos[0] = 0;
        }
        
        return string(sysErrText);
    }
    else {
        return string("Unknown error - no description.");
    }
#else
    // POSIX error codes
    
    static const int c_len(255);
    char errorText[c_len];
#if TGT_OS_hpux
    char* result = strerror(m_error);
#elif TGT_OS_linux
    // Threadsafe strerror.
    char* result = strerror_r(m_error, errorText, c_len);
#endif

    if (result == NULL) {
        ostringstream sstr;
        sstr << "Unknown system error: " << m_error;
        return sstr.str();
    }
    
    return string(result);
#endif
}


Member Data Documentation

Reimplemented from ivd_Exception.

Definition at line 211 of file ivderror.h.


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