Thursday, December 3, 2009

Exception Handling in Visual C++


Visual C++ supports three kinds of exception handling:

(1) C++ exception handling

(2) Structured exception handling

(3) MFC exceptions




When to Use Exceptions 


Three categories of outcomes can occur when a function is called during program execution: normal execution, erroneous execution, or abnormal execution. Each category is described below.


  Normal execution 


The function may execute normally and return. Some functions return a result code to the caller, which indicates the outcome of the function. The possible result codes are strictly defined for the function and represent the range of possible outcomes of the function. The result code can indicate success or failure or can even indicate a particular type of failure that is within the normal range of expectations. For example, a file-status function can return a code that indicates that the file does not exist. Note that the term "error code" is not used because a result code represents one of many expected outcomes.

     Erroneous execution 


The caller makes some mistake in passing arguments to the function or calls the function in an inappropriate context. This situation causes an error, and it should be detected by an assertion during program development. 



Abnormal execution 


Abnormal execution includes situations where conditions outside the program's control, such as low memory or I/O errors, are influencing the outcome of the function. Abnormal situations should be handled by catching and throwing exceptions.





















Exception class
Meaning
CMemoryException Class
Out-of-memory
CFileException Class
File exception
CArchiveException Class
Archive/Serialization exception
CNotSupportedException Class
Response to request for unsupported service
CResourceException Class
Windows resource allocation exception
CDaoException Class
Database exceptions (DAO classes)
CDBException Class
Database exceptions (ODBC classes)
COleException Class
OLE exceptions
COleDispatchException Class
Dispatch (automation) exceptions
CUserException Class
Exception that alerts the user with a message box, then throws a generic CException Class


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.