For example, COM programming uses the HRESULT return value to communicate errors to the caller. In C-style programming and in COM, error reporting is managed either by returning a value that represents an error code or a status code for a particular function, or by setting a global variable that the caller may optionally retrieve after every function call to see whether errors were reported. And, runtime errors that are beyond the control of programmer, for example, a "network service unavailable" error. Program errors are often divided into two categories: Logic errors that are caused by programming mistakes, for example, an "index out of range" error. Exceptions provide a formal, well-defined way for code that detects errors to pass the information up the call stack. It's especially true when the stack might contain several function calls between the function that detects the error, and the function that has the context to handle the error. In modern C++, in most scenarios, the preferred way to report and handle both logic errors and runtime errors is to use exceptions.
0 Comments
Leave a Reply. |