NokSync

KaarPoSoft

NokSyncLib.h File Reference


Detailed Description

Macros for error handling.


Defines

#define  NOKSYNC_CATCH_COMERROR(NMP)
#define  NOKSYNC_CATCH_EXCEPTION
#define  NOKSYNC_CHECK_HR(HR)
#define  NOKSYNC_MAX_ERROR_LENGTH   1024
#define  NOKSYNC_RETURN_OK
#define  NOKSYNC_TRY_COMERROR
#define  NOKSYNC_TRY_EXCEPTION

Functions

std::string  NmpErrorText (long)
  Return description of error for given NMP error number.

Define Documentation

#define NOKSYNC_CATCH_COMERROR ( NMP   ) 

Value:

catch (_com_error &ce) { \
                                *hResult=ce.Error(); \
                                char x[NOKSYNC_MAX_ERROR_LENGTH+1]; \
                                _snprintf(x, NOKSYNC_MAX_ERROR_LENGTH, "Unexpected _com_error 0x%x in %s", *hResult, __FUNCTION__); \
                                x[NOKSYNC_MAX_ERROR_LENGTH]='\0'; \
                                mLastError.Assign(x); \
                                try { \
                                        LPTSTR szErrMsg = NULL;  \
                                        long iFreeErrMsg = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, *hResult, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPTSTR)&szErrMsg, 0, NULL );  \
                                        if( (0 == iFreeErrMsg) || (NULL == szErrMsg) ) szErrMsg = "No error message\n";  \
                                        mLastError.Append("\n"); \
                                        mLastError.Append(szErrMsg); \
                                        if( iFreeErrMsg != 0 ) LocalFree( szErrMsg );  \
                                } catch (...) {} \
                                try { \
                                        *nmpResult =  NMP->GetLastError(); \
                                        mLastError.Append("\nNMP: "); \
                                mLastError.Append(NmpErrorText(*nmpResult).c_str()); \
                                } catch (...) {} \
                                        return NS_ERROR_UNEXPECTED; \
                        }
Catch block for COM errors

#define NOKSYNC_CATCH_EXCEPTION

Value:

catch (exception &e) { \
                        char x[NOKSYNC_MAX_ERROR_LENGTH+1]; \
                        _snprintf(x, NOKSYNC_MAX_ERROR_LENGTH, "Unexpected error in %s(%d): %s", __FUNCTION__, __LINE__, e.what()); \
                        x[NOKSYNC_MAX_ERROR_LENGTH]='\0'; \
                        mLastError.Assign(x); \
                        return NS_ERROR_UNEXPECTED; \
                } \
        } catch (...) { \
        mLastError.Assign("Unexpected error in " __FUNCTION__ ": Final Catch"); \
                return NS_ERROR_UNEXPECTED; \
        }
Default catch block

#define NOKSYNC_CHECK_HR ( HR   ) 

Value:

if (NS_FAILED(HR)) { \
                char x[NOKSYNC_MAX_ERROR_LENGTH+1]; \
                _snprintf(x, NOKSYNC_MAX_ERROR_LENGTH, "Unexpected hResult 0x%x in %s(%d)", HR, __FUNCTION__, __LINE__); \
                x[NOKSYNC_MAX_ERROR_LENGTH]='\0'; \
                mLastError.Assign(x); \
                return NS_ERROR_UNEXPECTED; }
Check HR (hResult) and return on error

#define NOKSYNC_MAX_ERROR_LENGTH   1024

Maximal length of error messages from NMP

#define NOKSYNC_RETURN_OK

Value:

mLastError.Assign("No error " __FUNCTION__); \
        return NS_OK;
Return OK

#define NOKSYNC_TRY_COMERROR

Value:

*hResult=ERROR_SUCCESS; \
                *nmpResult=0; \
                        try  \
Start of try block for COM errors

#define NOKSYNC_TRY_EXCEPTION

Value:

try { \
                try  \
Start of try block

Doxygen.org   SourceForge.net