www.pudn.com > DirectX source.zip > Exceptions.h


/*! 
	@file : Exceptions.h 
	This file contain headers of exception classes. 
 
	@author Sarmad Kh. Abdulla 
*/ 
//------------------------------------------------------------------------------ 
 
 
//! The base exception class 
/*! This class is the base class for all exception classes. It's used to enable 
	the user to use one exception handler to catch all types of exceptions. */ 
class CException 
{ 
public: 
	//! Show the exception message 
	/*! This pure virtual function should be overloaded by any inherited exception 
		class to provide its own exception message. It's better to show the message 
		in a message box but it's not a necessity. */ 
	virtual void ShowMessage( HWND hwnd ) = 0; 
}; 
 
//! File exception class 
/*! This class is an exception class for file errors. It's used to acknowledge an 
	error while opening a file. */ 
class CFileException : public CException 
{ 
public: 
	//! Construct the class with a file name. 
	/*! This constructor takes a pointer to a string containing the name of the file  
		on which an error occured. This function stores this filename for later use 
		with ShowMessage. */ 
	CFileException( const char * p ) 
	{ 
		FileName = p; 
	} 
	//! Show a file open error message 
	virtual void ShowMessage( HWND hwnd ); 
protected: 
	string FileName;	//!< The name of the file that has the error. 
}; 
 
//! Memory exception class 
/*! This class is an exception class for 'not enough memory'. It's used in cases where 
	a memory allocation fails. */ 
class CMemoryException : public CException 
{ 
public: 
	//! Show a 'not enough memory' message 
	virtual void ShowMessage( HWND hwnd ); 
}; 
 
//! Custom message exception class 
/*! This class is an exception class holding a custom message. Any message can be used 
	with this class. */ 
class CCustomException : public CException 
{ 
public: 
	//! Construct the class with a message 
	/*! This function takes a pointer to a message to be shown to the user exactly and 
		without any changes when ShowMessage is called */ 
	CCustomException( const char * p ) 
	{ 
		Message = p; 
	} 
	//! Show the custom message 
	virtual void ShowMessage( HWND hwnd ); 
protected: 
	string Message;	//!< The message to be shown to the user. 
}; 
 
//! DX error exception class 
/*! This class is an exception class holding a DX error message. */ 
class CDXException : public CException 
{ 
public: 
	//! Construct the class with a D3D error code and a custom message 
	/*! This function takes a pointer to a message to be included in the class with 
		the error code. */ 
	CDXException( const char * p, HRESULT errorcode ) 
	{ 
		Message = p; 
		ErrorCode = errorcode; 
	} 
	//! Show the error message 
	virtual void ShowMessage( HWND hwnd ); 
	//! Returns the error code value 
	HRESULT GetErrorCode( void ) 
	{ 
		return ErrorCode; 
	} 
protected: 
	string Message;		//!< A text message 
	HRESULT ErrorCode;	//!< The D3D error code 
};