Error Handling Strategies
Because interface methods are virtual, it is not possible for a caller to know the full set of values that may be returned from any one call. One implementation of a method may return five values; another may return eight.
The documentation lists common values that may be returned for each method; these are the values that you must check for and handle in your code because they have special meanings. Other values may be returned, but because they are not meaningful, you do not need to write special code to handle them. A simple check for zero or nonzero is adequate.
HRESULT Values
The return value of COM functions and methods is an HRESULT. The values of some HRESULTs have been changed in COM to eliminate all duplication and overlapping with the system error codes. Those that duplicate system error codes have been changed to FACILITY_WIN32, and those that overlap remain in FACILITY_NULL. Common HRESULT values and their values are listed in the following table.
HRESULT | Value | Description |
---|---|---|
E_ABORT |
0x80004004 |
The operation was aborted because of an unspecified error. |
E_ACCESSDENIED |
0x80070005 |
A general access-denied error. |
E_FAIL |
0x80004005 |
An unspecified failure has occurred. |
E_HANDLE |
0x80070006 |
An invalid handle was used. |
E_INVALIDARG |
0x80070057 |
One or more arguments are invalid. |
E_NOINTERFACE |
0x80004002 |
The QueryInterface method did not recognize the requested interface. The interface is not supported. |
E_NOTIMPL |
0x80004001 |
The method is not implemented. |
E_OUTOFMEMORY |
0x8007000E |
The method failed to allocate necessary memory. |
E_PENDING |
0x8000000A |
The data necessary to complete the operation is not yet available. |
E_POINTER |
0x80004003 |
An invalid pointer was used. |
E_UNEXPECTED |
0x8000FFFF |
A catastrophic failure has occurred. |
S_FALSE |
0x00000001 |
The method succeeded and returned the boolean value FALSE. |
S_OK |
0x00000000 |
The method succeeded. If a boolean return value is expected, the returned value is TRUE. |
Network Errors
If the first four digits of the error code are 8007, this indicates a system or network error. You can use the net command to decode these types of errors. To decode the error, first convert the last four digits of the hexadecimal error code to decimal. Then, at the command prompt, type the following, where decimal code is replaced with the return value you want to decode:
net helpmsg <decimal_code>
The net command returns a description of the error. For example, if COM returns the error 8007054B, convert the 054B to decimal (1355). Then type the following:
net helpmsg 1355
The net command returns the error description: "The specified domain did not exist".