
how to throw exceptions from a COM component?
The first, you must add Support Error Info when creating object with ATL
Wizard and then implement the code stuff for creating Error object whenever
there is a error occure, that's only for VB client.
If you want to thow exception for handling with try/catch in VC++ client,
add the statement
_com_raise_error(E_FAIL, pErrorInfo);
in this code stuff.
Quote:
> When u add a new ATL component to your project , it asks u to select
couple
> of options at that point u have to check "Support ISupportErrorInfo" .
Now
> ,
> try
> {
> // call method
> }
> catch(...)
> {
> Error("Error string");
> return E_FAIL;
> }
> Now in your VB client method :
> On Error Goto oops
> ' create your com object
> ....
> ' do your business
> .....
> oops:
> ' Use VB Err object and do whatever u want
> ' like here :
> MsgBox Err.Description , "Error from COM"
> End Sub
> > Does anyone know how I can throw an exception from a ATL/COM component
so
> > that it can be "caught" correctly on a VB client?
> > Currently my ATL component uses the AfxThrowOleDispatchException() to
> throw
> > an exception, but my VB app crashes as soon as this function is called
> (even
> > though I have an error handler setup with "on error goto
MyErrorHandler").
> > If you know how to solve this problem, I would appreciate hearing from
> > you...
> > Thanks in advance,
> > Arvind.