Partager via


CSimpleException Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CSimpleException Class.

This class is a base class for resource-critical MFC exceptions.

Syntax

class AFX_NOVTABLE CSimpleException : public CException  

Members

Public Constructors

Name Description
CSimpleException::CSimpleException The constructor.

Public Methods

Name Description
CSimpleException::GetErrorMessage Provides text about an error that has occurred.

Remarks

CSimpleException is the base class for resource-critical MFC exceptions and handles the ownership and initialization of an error message. The following classes use CSimpleException as their base class:

CMemoryException Class Out-of-memory exception
CNotSupportedException Class Requests for an unsupported operation
CResourceException Class Windows resource not found or not creatable
CUserException Class Exception that indicates a resource could not be found
CInvalidArgException Class Exception that indicates an invalid argument

Because CSimpleException is an abstract base class, you cannot declare a CSimpleException object directly. Instead, you must declare derived objects such as those in the previous table. If you are declaring your own derived class, use the previous classes as a model.

For more information, see the CException Class topic and Exception Handling (MFC).

Inheritance Hierarchy

CObject

CException

CSimpleException

Requirements

Header: afx.h

CSimpleException::CSimpleException

The constructor.

CSimpleException();  
explicit CSimpleException(BOOL bAutoDelete);
```  
  
### Parameters  
 `bAutoDelete`  
 Specify **TRUE** if the memory for the `CSimpleException` object has been allocated on the heap. This will cause the `CSimpleException` object to be deleted when the **Delete** member function is called to delete the exception. Specify **FALSE** if the `CSimpleException` object is on the stack or is a global object. In this case, the `CSimpleException` object will not be deleted when the **Delete** member function is called.  
  
### Remarks  
 You would normally never need to call this constructor directly. A function that throws an exception should create an instance of a `CException`-derived class and call its constructor, or it should use one of the MFC throw functions, such as [AfxThrowFileException]--brokenlink--(../Topic/not%20found.md#afxthrowfileexception), to throw a predefined type.  
  
##  <a name="csimpleexception__geterrormessage"></a>  CSimpleException::GetErrorMessage  
 Call this member function to provide text about an error that has occurred.  
  

virtual BOOL GetErrorMessage( LPTSTR lpszError, UINT nMaxError, PUNIT pnHelpContext = NULL);

  
### Parameters  
 `lpszError`  
 A pointer to a buffer that will receive an error message.  
  
 `nMaxError`  
 The maximum number of characters the buffer can hold, including the **NULL** terminator.  
  
 `pnHelpContext`  
 The address of a **UINT** that will receive the help context ID. If **NULL**, no ID will be returned.  
  
### Return Value  
 Nonzero if the function is successful; otherwise 0 if no error message text is available.  
  
### Remarks  
 For more information, see [CException::GetErrorMessage](../Topic/CFileException%20Class.md#cfileexception__geterrormessage).  
  
## See Also  
 [Hierarchy Chart](../Topic/Hierarchy%20Chart.md)   
 [CException Class](../Topic/CException%20Class.md)   
 [Exception Handling](../Topic/Exception%20Handling%20in%20MFC.md)