Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C#

Windows Development in C++, COM API Clients

Rate me:
Please Sign up or sign in to vote.
4.98/5 (31 votes)
3 Jan 2015CPOL7 min read 62.8K   1.6K   106  
Using the Facade Pattern to simplify development with COM based APIs
#pragma once
#ifndef __HWINEXCEPTION_H__
#define __HWINEXCEPTION_H__

#include "hwindef.h"


namespace harlinn
{
    namespace windows
    {
        class ExceptionData;
        class Exception : public std::exception
        {
            ExceptionData* data;
            HWIN_EXPORT static AnsiString empty;
        protected:
            HWIN_EXPORT const ExceptionData* GetExceptionData( ) const;
            HWIN_EXPORT ExceptionData* GetExceptionData( );
            HWIN_EXPORT String GetData( int id ) const;
            HWIN_EXPORT Exception& SetData( int id, const char* theValue );
            HWIN_EXPORT Exception& SetData( int id, const wchar_t* theValue );
            HWIN_EXPORT Exception& SetData( int id, const String& theValue );
        public:
            HWIN_EXPORT static String Format( const char*fmt, ... );
            HWIN_EXPORT static String Format( const wchar_t* fmt, ... );
            static const HRESULT HRESULTForExceptionType = COR_E_EXCEPTION;
        protected:
            HWIN_EXPORT static String FormatList( const char*fmt, va_list args );
            HWIN_EXPORT static String FormatList( const wchar_t*fmt, va_list args );
        public:
            HWIN_EXPORT explicit Exception( );
            HWIN_EXPORT Exception( const Exception& theException );
            HWIN_EXPORT explicit Exception( const char* theMessage );
            HWIN_EXPORT explicit Exception( const wchar_t* theMessage );
            HWIN_EXPORT explicit Exception( const String& theMessage );
            HWIN_EXPORT Exception( const char* theMessage, const Exception& theInnerException );
            HWIN_EXPORT Exception( const wchar_t* theMessage, const Exception& theInnerException );
            HWIN_EXPORT Exception( long long theCode, const char* theMessage );
            HWIN_EXPORT Exception( long long theCode, const wchar_t* theMessage );
            HWIN_EXPORT Exception( long long theCode, const String& theMessage );
            HWIN_EXPORT Exception( HRESULT hResult, long long theCode, const char* theMessage );
            HWIN_EXPORT Exception( HRESULT hResult, long long theCode, const wchar_t* theMessage );
            HWIN_EXPORT Exception( HRESULT hResult, long long theCode, const String& theMessage );
            HWIN_EXPORT virtual ~Exception( );

            HWIN_EXPORT Exception& operator = ( const Exception& theException );

            HWIN_EXPORT virtual const char* what( ) const;

            HWIN_EXPORT String Message( ) const;
            HWIN_EXPORT Exception& SetMessage( const char* theValue );
            HWIN_EXPORT Exception& SetMessage( const wchar_t* theValue );
            HWIN_EXPORT Exception& SetMessage( const String& theValue );

            HWIN_EXPORT String GetHelpLink( ) const;
            HWIN_EXPORT Exception& SetHelpLink( const char* theValue );
            HWIN_EXPORT Exception& SetHelpLink( const wchar_t* theValue );
            HWIN_EXPORT Exception& SetHelpLink( const String& theValue );

            HWIN_EXPORT HRESULT GetHRESULT( ) const;
            HWIN_EXPORT Exception& SetHRESULT( HRESULT theValue );

            HWIN_EXPORT long long GetCode( ) const;
            HWIN_EXPORT Exception& SetCode( long long theValue );

            HWIN_EXPORT const ExceptionData* GetInnerException( ) const;
            HWIN_EXPORT Exception& SetInnerException( const Exception& theValue );

            HWIN_EXPORT String GetSource( ) const;
            HWIN_EXPORT Exception& SetSource( const char* theValue );
            HWIN_EXPORT Exception& SetSource( const wchar_t* theValue );
            HWIN_EXPORT Exception& SetSource( const String& theValue );

        };

#define HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( className ) \
HWIN_EXPORT explicit className (); \
HWIN_EXPORT className (const className & theException);  \
HWIN_EXPORT explicit className (const char* theMessage);  \
HWIN_EXPORT explicit className (const wchar_t* theMessage);  \
HWIN_EXPORT explicit className (const String& theMessage);  \
HWIN_EXPORT className ( long long theCode, const char* theMessage ); \
HWIN_EXPORT className ( long long theCode, const wchar_t* theMessage ); \
HWIN_EXPORT className ( long long theCode, const String& theMessage );  \
HWIN_EXPORT className ( HRESULT hResult, long long theCode, const char* theMessage );  \
HWIN_EXPORT className ( HRESULT hResult, long long theCode, const wchar_t* theMessage );  \
HWIN_EXPORT className ( HRESULT hResult, long long theCode, const String& theMessage );  \
HWIN_EXPORT className (const char* theMessage, const Exception& theInnerException);  \
HWIN_EXPORT className (const wchar_t* theMessage, const Exception& theInnerException);  \
HWIN_EXPORT className & operator = (const className & theException) 

#define HARLINN_WINDOWS_IMPLEMENT_STANDARD_EXCEPTION_MEMBERS( className ) \
HWIN_EXPORT className :: className () : Base() { SetHRESULT( className :: HRESULTForExceptionType); } \
HWIN_EXPORT className :: className (const className & theException) : Base(theException) { }  \
HWIN_EXPORT className :: className (const char* theMessage) : Base(theMessage) { SetHRESULT( className :: HRESULTForExceptionType); }  \
HWIN_EXPORT className :: className (const wchar_t* theMessage) : Base(theMessage) { SetHRESULT( className :: HRESULTForExceptionType); }  \
HWIN_EXPORT className :: className (const String& theMessage) : Base(theMessage) { SetHRESULT( className :: HRESULTForExceptionType); }  \
HWIN_EXPORT className :: className (const char* theMessage, const Exception& theInnerException) : Base(theMessage,theInnerException) { SetHRESULT( className :: HRESULTForExceptionType); }  \
HWIN_EXPORT className :: className (const wchar_t* theMessage, const Exception& theInnerException) : Base(theMessage,theInnerException) { SetHRESULT( className :: HRESULTForExceptionType); }  \
HWIN_EXPORT className :: className ( long long theCode, const char* theMessage ) : Base(className :: HRESULTForExceptionType, theCode, theMessage) { }  \
HWIN_EXPORT className :: className ( long long theCode, const wchar_t* theMessage ) : Base(className :: HRESULTForExceptionType, theCode, theMessage) { }  \
HWIN_EXPORT className :: className ( long long theCode, const String& theMessage ) : Base(className :: HRESULTForExceptionType, theCode, theMessage) { }  \
HWIN_EXPORT className :: className ( HRESULT hResult, long long theCode, const char* theMessage ) : Base(hResult, theCode, theMessage) { }  \
HWIN_EXPORT className :: className ( HRESULT hResult, long long theCode, const wchar_t* theMessage ) : Base(hResult, theCode, theMessage) { }  \
HWIN_EXPORT className :: className ( HRESULT hResult, long long theCode, const String& theMessage ) : Base(hResult, theCode, theMessage) { }  \
HWIN_EXPORT className & className :: operator = (const className & theException ) { Base :: operator = ( reinterpret_cast< const Base & > (theException) ); return *this; }  

        class SystemException : public Exception
        {
        public:
            typedef Exception Base;
            static const HRESULT HRESULTForExceptionType = COR_E_SYSTEM;
            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SystemException );
        };

        class AppDomainUnloadedException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = 0x80131015; //MSEE_E_APPDOMAINUNLOADED;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( AppDomainUnloadedException );
        };

        class ArrayTypeMismatchException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_ARRAYTYPEMISMATCH;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ArrayTypeMismatchException );
        };


        class AccessViolationException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = E_POINTER;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( AccessViolationException );
        };

        class AggregateException : public Exception
        {
        public:
            typedef Exception Base;
            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( AggregateException );
        };

        class ApplicationException : public Exception
        {
        public:
            typedef Exception Base;

            static const HRESULT HRESULTForExceptionType = COR_E_APPLICATION;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ApplicationException );
        };

        class ArgumentException : public SystemException
        {
        protected:
            static const int ParamNameId = 1000;
        public:
            typedef SystemException Base;

            static const HRESULT HRESULTForExceptionType = COR_E_ARGUMENT;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ArgumentException );

            HWIN_EXPORT ArgumentException( const char* message, const char* argument );
            HWIN_EXPORT ArgumentException( const wchar_t* message, const wchar_t* argument );
            HWIN_EXPORT ArgumentException( const String& message, const char* argument );
            HWIN_EXPORT ArgumentException( const String& message, const wchar_t* argument );
            HWIN_EXPORT ArgumentException( const String& message, const String& argument );

            HWIN_EXPORT String GetParamName( ) const;
        };

        class ArgumentNullException : public ArgumentException
        {
        public:
            typedef ArgumentException Base;
            static const HRESULT HRESULTForExceptionType = E_POINTER;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ArgumentNullException );

            HWIN_EXPORT ArgumentNullException( const char* argument, const char* message );
            HWIN_EXPORT ArgumentNullException( const wchar_t* argument, const wchar_t* message );
            HWIN_EXPORT ArgumentNullException( const char* argument, const String& message );
            HWIN_EXPORT ArgumentNullException( const wchar_t* argument, const String& message );
            HWIN_EXPORT ArgumentNullException( const String& argument, const String& message );

        };

        class ArgumentOutOfRangeException : public ArgumentException
        {
        public:
            typedef ArgumentException Base;

            static const HRESULT HRESULTForExceptionType = COR_E_ARGUMENTOUTOFRANGE;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ArgumentOutOfRangeException );

            HWIN_EXPORT ArgumentOutOfRangeException( const char* argument, const char* message );
            HWIN_EXPORT ArgumentOutOfRangeException( const wchar_t* argument, const wchar_t* message );
            HWIN_EXPORT ArgumentOutOfRangeException( const char* argument, const String& message );
            HWIN_EXPORT ArgumentOutOfRangeException( const wchar_t* argument, const String& message );
            HWIN_EXPORT ArgumentOutOfRangeException( const String& argument, const String& message );

        };


        class ArithmeticException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_ARITHMETIC;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ArithmeticException );

        };

        class BadImageFormatException : public SystemException
        {
        public:
            typedef SystemException Base;

            static const HRESULT HRESULTForExceptionType = COR_E_BADIMAGEFORMAT;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( BadImageFormatException );
        };

        class CannotUnloadAppDomainException : public SystemException
        {
        public:
            typedef SystemException Base;

            static const HRESULT HRESULTForExceptionType = COR_E_CANNOTUNLOADAPPDOMAIN;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( CannotUnloadAppDomainException );
        };

        class ContextMarshalException : public SystemException
        {
        public:
            typedef SystemException Base;

            static const HRESULT HRESULTForExceptionType = COR_E_CONTEXTMARSHAL;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ContextMarshalException );
        };



        class DataMisalignedException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_DATAMISALIGNED;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DataMisalignedException );
        };


        class ExecutionEngineException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_EXECUTIONENGINE;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ExecutionEngineException );
        };


        class TypeLoadException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_TYPELOAD;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TypeLoadException );
        };

        class DivideByZeroException : public ArithmeticException
        {
        public:
            typedef ArithmeticException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_DIVIDEBYZERO;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DivideByZeroException );
        };

        class DllNotFoundException : public TypeLoadException
        {
        public:
            typedef TypeLoadException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_DLLNOTFOUND;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DllNotFoundException );
        };

        class DuplicateWaitObjectException : public ArgumentException
        {
        public:
            typedef ArgumentException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_DUPLICATEWAITOBJECT;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DuplicateWaitObjectException );
        };

        class EntryPointNotFoundException : public TypeLoadException
        {
        public:
            typedef TypeLoadException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_TYPELOAD;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( EntryPointNotFoundException );
        };

        class MemberAccessException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_MEMBERACCESS;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MemberAccessException );
        };

        class FieldAccessException : public MemberAccessException
        {
        public:
            typedef MemberAccessException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_FIELDACCESS;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( FieldAccessException );
        };


        class FormatException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_FORMAT;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( FormatException );
        };

        class IndexOutOfRangeException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_INDEXOUTOFRANGE;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( IndexOutOfRangeException );
        };


        class InsufficientExecutionStackException : public SystemException
        {
        public:
            typedef SystemException Base;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InsufficientExecutionStackException );
        };

        class OutOfMemoryException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_OUTOFMEMORY;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( OutOfMemoryException );

        };

        class InsufficientMemoryException : public OutOfMemoryException
        {
        public:
            typedef OutOfMemoryException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_INSUFFICIENTMEMORY;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InsufficientMemoryException );
        };

        class InvalidCastException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_INVALIDCAST;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidCastException );
        };


        class InvalidOperationException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_INVALIDOPERATION;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidOperationException );
        };

        class InvalidProgramException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_INVALIDPROGRAM;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidProgramException );
        };

        class InvalidTimeZoneException : public Exception
        {
        public:
            typedef Exception Base;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidTimeZoneException );
        };

        class MethodAccessException : public MemberAccessException
        {
        public:
            typedef MemberAccessException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_METHODACCESS;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MethodAccessException );
        };

        class MissingMemberException : public MemberAccessException
        {
        public:
            typedef MemberAccessException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_MISSINGMEMBER;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MissingMemberException );
        };

        class MissingFieldException : public MissingMemberException
        {
        public:
            typedef MissingMemberException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_MISSINGFIELD;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MissingFieldException );
        };


        class MissingMethodException : public MissingMemberException
        {
        public:
            typedef MissingMemberException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_MISSINGMETHOD;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MissingMethodException );
        };

        class MulticastNotSupportedException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_MULTICASTNOTSUPPORTED;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MulticastNotSupportedException );
        };

        class NotFiniteNumberException : public ArithmeticException
        {
        public:
            typedef ArithmeticException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_NOTFINITENUMBER;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( NotFiniteNumberException );
        };

        class NotImplementedException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = E_NOTIMPL;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( NotImplementedException );
        };

        class NotSupportedException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_NOTSUPPORTED;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( NotSupportedException );
        };

        class NullReferenceException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_NULLREFERENCE;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( NullReferenceException );
        };

        class OperationCanceledException : public SystemException
        {
        public:
            typedef SystemException Base;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( OperationCanceledException );
        };

        class OverflowException : public ArithmeticException
        {
        public:
            typedef ArithmeticException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_OVERFLOW;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( OverflowException );
        };


        class PlatformNotSupportedException : public NotSupportedException
        {
        public:
            typedef NotSupportedException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_PLATFORMNOTSUPPORTED;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( PlatformNotSupportedException );
        };

        class RankException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_RANK;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( RankException );
        };


        class StackOverflowException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_STACKOVERFLOW;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( StackOverflowException );
        };



        class TimeoutException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_TIMEOUT;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TimeoutException );
        };


        class TypeInitializationException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_TYPEINITIALIZATION;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TypeInitializationException );
        };

        class TypeUnloadedException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_TYPEUNLOADED;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TypeUnloadedException );
        };

        class UnauthorizedAccessException : public SystemException
        {
        public:
            typedef SystemException Base;
            static const HRESULT HRESULTForExceptionType = COR_E_UNAUTHORIZEDACCESS;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( UnauthorizedAccessException );
        };

        class UriFormatException : public FormatException
        {
        public:
            typedef FormatException Base;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( UriFormatException );
        };

        class UriTemplateMatchException : public SystemException
        {
        public:
            typedef SystemException Base;

            HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( UriTemplateMatchException );
        };

        namespace IO
        {
            class IOException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_IO;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( IOException );
            };

            class DirectoryNotFoundException : public IOException
            {
            public:
                typedef IOException Base;
                static const HRESULT HRESULTForExceptionType = STG_E_PATHNOTFOUND;
                static const HRESULT HRESULTForExceptionType2 = COR_E_DIRECTORYNOTFOUND;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DirectoryNotFoundException );
            };


            class DriveNotFoundException : public IOException
            {
            public:
                typedef IOException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_DIRECTORYNOTFOUND;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DriveNotFoundException );
            };

            class EndOfStreamException : public IOException
            {
            public:
                typedef IOException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_ENDOFSTREAM;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( EndOfStreamException );
            };

            class FileLoadException : public IOException
            {
            public:
                typedef IOException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_FILELOAD;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( FileLoadException );
            };


            class FileNotFoundException : public IOException
            {
            public:
                typedef IOException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_FILENOTFOUND;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( FileNotFoundException );
            };

            class PathTooLongException : public IOException
            {
            public:
                typedef IOException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_PATHTOOLONG;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( PathTooLongException );
            };

            class PipeException : public IOException
            {
            public:
                typedef IOException Base;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( PipeException );
            };

            namespace IsolatedStorage
            {
                class IsolatedStorageException : public Exception
                {
                public:
                    typedef Exception Base;
                    static const HRESULT HRESULTForExceptionType = ISS_E_ISOSTORE;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( IsolatedStorageException );
                };

            }
        }



        namespace Reflection
        {
            class CustomAttributeFormatException : public FormatException
            {
            public:
                typedef FormatException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_FORMAT;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( CustomAttributeFormatException );
            };

            class InvalidFilterCriteriaException : public ApplicationException
            {
            public:
                typedef ApplicationException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_INVALIDFILTERCRITERIA;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidFilterCriteriaException );
            };

            class ReflectionTypeLoadException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_REFLECTIONTYPELOAD;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ReflectionTypeLoadException );
            };

            class TargetException : public ApplicationException
            {
            public:
                typedef ApplicationException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_TARGET;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TargetException );
            };

            class TargetInvocationException : public ApplicationException
            {
            public:
                typedef ApplicationException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_TARGETINVOCATION;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TargetInvocationException );
            };

            class TargetParameterCountException : public ApplicationException
            {
            public:
                typedef ApplicationException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_TARGETPARAMCOUNT;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( TargetParameterCountException );
            };




        }

        namespace Runtime
        {
            namespace InteropServices
            {
                class ExternalException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = E_FAIL;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ExternalException );
                };

                class COMException : public ExternalException
                {
                public:
                    typedef ExternalException Base;
                    static const HRESULT HRESULTForExceptionType = E_FAIL;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( COMException );
                };

                class InvalidComObjectException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_INVALIDCOMOBJECT;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidComObjectException );
                };

                class InvalidOleVariantTypeException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_INVALIDOLEVARIANTTYPE;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( InvalidOleVariantTypeException );
                };

                class MarshalDirectiveException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_MARSHALDIRECTIVE;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MarshalDirectiveException );
                };

                class SafeArrayTypeMismatchException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_SAFEARRAYTYPEMISMATCH;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SafeArrayTypeMismatchException );
                };

                class SafeArrayRankMismatchException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_SAFEARRAYRANKMISMATCH;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SafeArrayRankMismatchException );
                };

                class SEHException : public ExternalException
                {
                public:
                    typedef ExternalException Base;
                    static const HRESULT HRESULTForExceptionType = E_FAIL;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SEHException );
                };


            }

            namespace Remoting
            {
                class RemotingException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_REMOTING;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( RemotingException );
                };


                class RemotingTimeoutException : public RemotingException
                {
                public:
                    typedef RemotingException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_REMOTING;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( RemotingTimeoutException );
                };

                class ServerException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_SERVER;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ServerException );
                };

                namespace MetadataServices
                {
                    class SUDSGeneratorException : public Exception
                    {
                    public:
                        typedef Exception Base;
                        static const HRESULT HRESULTForExceptionType = COR_E_EXCEPTION;

                        HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SUDSGeneratorException );
                    };

                    class SUDSParserException : public Exception
                    {
                    public:
                        typedef Exception Base;
                        static const HRESULT HRESULTForExceptionType = COR_E_EXCEPTION;

                        HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SUDSParserException );
                    };
                }

            }

            namespace Serialization
            {
                class SerializationException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = COR_E_SERIALIZATION;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SerializationException );
                };
            }
        }

        namespace Data
        {
            namespace Common
            {
                class DbException : public Runtime::InteropServices::ExternalException
                {
                public:
                    typedef Runtime::InteropServices::ExternalException Base;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( DbException );
                };
            }

            namespace OracleClient
            {
                class OracleException : public Data::Common::DbException
                {
                public:
                    typedef Data::Common::DbException Base;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( OracleException );
                };
            }

        }

        namespace Messaging
        {
            class MessageQueueException : public Runtime::InteropServices::ExternalException
            {
            public:
                typedef Runtime::InteropServices::ExternalException Base;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MessageQueueException );
            };
        }



        namespace Resources
        {
            class MissingManifestResourceException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_MISSINGMANIFESTRESOURCE;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( MissingManifestResourceException );
            };

        }

        namespace Security
        {

            class SecurityException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_SECURITY;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SecurityException );
            };

            class VerificationException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_VERIFICATION;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( VerificationException );
            };



            namespace Cryptography
            {
                class CryptographicException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = NTE_FAIL;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( CryptographicException );
                };

                class CryptographicUnexpectedOperationException : public CryptographicException
                {
                public:
                    typedef CryptographicException Base;
                    static const HRESULT HRESULTForExceptionType = CORSEC_E_CRYPTO_UNEX_OPER;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( CryptographicUnexpectedOperationException );
                };

            }

            namespace Policy
            {
                class PolicyException : public SystemException
                {
                public:
                    typedef SystemException Base;
                    static const HRESULT HRESULTForExceptionType = CORSEC_E_POLICY_EXCEPTION;

                    HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( PolicyException );
                };
            }
        }

        namespace Threading
        {
            class SynchronizationLockException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_SYNCHRONIZATIONLOCK;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( SynchronizationLockException );
            };

            class ThreadAbortException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_THREADABORTED;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ThreadAbortException );
            };

            class ThreadInterruptedException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_THREADINTERRUPTED;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ThreadInterruptedException );
            };

            class ThreadStateException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_THREADSTATE;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ThreadStateException );
            };

            class ThreadStopException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_THREADSTOP;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( ThreadStopException );
            };


            class WaitHandleCannotBeOpenedException : public SystemException
            {
            public:
                typedef SystemException Base;
                static const HRESULT HRESULTForExceptionType = COR_E_WAITHANDLECANNOTBEOPENED;

                HARLINN_WINDOWS_DECLARE_STANDARD_EXCEPTION_MEMBERS( WaitHandleCannotBeOpenedException );
            };






        }



        HWIN_EXPORT void CheckHRESULT( HRESULT hresult );
        HWIN_EXPORT void ThrowLastOSError( );
        HWIN_EXPORT void ThrowOSError( DWORD errorId );
        HWIN_EXPORT void ThrowNoInterface( );
        HWIN_EXPORT void ThrowPointerIsNULL( );
        HWIN_EXPORT void ThrowInvalidHandle( );
        HWIN_EXPORT HRESULT HRESULTFromException( const std::exception& exception );

        template <typename T>
        inline void CheckPointerNotNull( T* ptr )
        {
            if ( !ptr )
            {
                ThrowPointerIsNULL( );
            }
        }

        template <typename T>
        inline void CheckPointerNotNull( std::shared_ptr<T> ptr )
        {
            if ( !ptr )
            {
                ThrowPointerIsNULL( );
            }
        }


    };
};

#endif //__HWINEXCEPTION_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions