///////////////////////////////////////////////////////////////////////
// Header file: "Except.h"
//
// (C) Copyright 2002, RightMark Gathering.  All Rights Reserved.
//
// @Author: Konstantin Mironovich (km) develop@rightmark3d.org
//   derivation work from original code by Alex Simkin (1998)
//
// Purpose: 
//   Implements Structured Exception Handling mapping into C++ exceptions. 
//
// History: 
//   2002/01/10 created. (km)
//
///////////////////////////////////////////////////////////////////////

#pragma once

class TOOLS_PUBLIC CException
{
public:
    CException()
        : m_IsStatic(false)
        , m_hResult(S_FALSE)
    {
    }

    CException(HRESULT hResult)
        : m_IsStatic(false)
        , m_hResult(hResult)
    {
    }

    CException(bool bStatic, HRESULT hResult)
        : m_IsStatic(bStatic)
        , m_hResult(hResult)
    {
    }

    virtual ~CException() {};

public:
    operator HRESULT()
    {
        return m_hResult;
    }

    void Delete()
    {
        if (!m_IsStatic)
            delete this;
    }

    virtual void GetErrorMessage(LPTSTR lpszError, DWORD nSize);
	virtual int ReportError(UINT nType = MB_OK, LPCTSTR pFileName = __FILE__
                            , int nLine = __LINE__);

public:
    bool    m_IsStatic;
    HRESULT m_hResult;
};

class TOOLS_PUBLIC CMemoryException : public CException
{
public:
    CMemoryException();
};

class TOOLS_PUBLIC CResourceException : public CException
{
public:
    CResourceException();
};

class TOOLS_PUBLIC CNotImplementedException : public CException
{
public:
    CNotImplementedException();
};

class TOOLS_PUBLIC CRunTimeException : public CException
{
public:
    CRunTimeException(UINT uiCode)
        : CException(uiCode) {}
};

void TOOLS_PUBLIC WINAPI ThrowException(HRESULT);
void TOOLS_PUBLIC WINAPI ThrowException(int);
void TOOLS_PUBLIC WINAPI ThrowMemoryException();
void TOOLS_PUBLIC WINAPI ThrowResourceException();
void TOOLS_PUBLIC WINAPI ThrowNotImplementedException();
