Article ID: 175784 - Last Review: December 30, 2005 - Revision: 5.0 How to replace #import's exception raising mechanism in Visual C++This article was previously published under Q175784 Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model
that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code
model. SUMMARY Using #import to create your client application introduces
exception handling through the _com_error exception class when a wrapper for an
object's method encounters a failed HRESULT. You might have valid reasons to
replace this mechanism with your own implementation. MORE INFORMATION There are two ways to use #import and not have it raise
exceptions for failed HRESULTS. The first is to use the raw_interfaces_only
clause with the #import statement. However, this negates some of the advantages
of the wrapper classes that #import provides. The second technique is by providing your own implementation for _com_raise_error, which has the following prototype and default implementation: Below is an example of implementation of #import's exception raising function: Note: Currently our compiler ignores a function exception-specification
and generates the warning: This code attempts to open an ADO connection object
without providing any valid connection information. By replacing
_com_raise_error, you prevented the _com_error from being raised. warning C4290: C++
Exception Specification ignored. However, just because you have replaced this function, you may still need to trap for exceptions. Consider the code snippet below. APPLIES TO
| Article Translations
|
Back to the top
