
ATL server throw exception
In
Visual C++ 6, I select ATL COM AppWizard to create a new project.
I added a simple com class, CMycomclass, with 1 method.
[id(1), helpstring("method foo")] HRESULT foo([in] long id, [out,
retval] long *pVal);
Here is the implementation of foo:
STDMETHODIMP CMycomclass::foo( long id, long* pVal)
{
IDBInitialize* pIDBInitialize = NULL;
try {
HRESULT hr = ::CoCreateInstance(CLSID_OraOLEDB, NULL,
CLSCTX_INPROC_SERVER, IID_IDBInitialize, (void**)ppIDBInitialize);
Quote:
}
catch (_com_error& e)
{
hr = e.Error();
Quote:
}
catch (...)
{
hr = E_FAIL;
Quote:
}
*pVal = hr;
return hr;
Quote:
}
There is no real purpose to this ATL COM server. It does try to
instantiate the Oracle Provider for OLEDB. But doesn't try to actually
connect or anything useful. It just has the one call to
CoCreateInstance. I purposefully ran this on a PC where the Oracle
Provider WAS NOT installed, so the CoCreateInstance should fail.
I then created a simple VB project to call this ATL server and call
this method, and "watch" it fail:
Sub MyVBSub( )
On Error GoTo err_handler
Dim z As MyATLSERVERLib.MyComClass
Set z = New MyATLSERVERLib.MyComClass
Dim retval As Long
Dim id As Long
id = 1
retval = 0
retval = z.foo(id)
...
err_handler:
....
End Sub
When I step through the project , why does this call z.foo throw an
exception . The call to foo causes a jump to the err_handler, the
error being 429 ActiveX can't create component.
That is EXPECTED because the Oracle Provider is not installed and so
when the ATL COM Server method foo attempts to call CoCreateInstance
it fails, That is all as it should be, But why does it cause the VB
error handler to be invoked.
I use try-catch inside the ATL COM server. Shouldn't that be catching
any exceptions and set retval. So that when VB calls the one method
and the method throws , it nicely sets retval and returns to VB
without triggering the VB exception handling.????
cbb