how to throw exceptions from a COM component? 
Author Message
 how to throw exceptions from a COM component?

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.



Sat, 08 May 2004 07:41:39 GMT  
 how to throw exceptions from a COM component?
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
Quote:
}

catch(...)
{
    Error("Error string");
    return E_FAIL;

Quote:
}

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


Quote:
> 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.



Sat, 08 May 2004 09:55:09 GMT  
 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.



Sat, 08 May 2004 10:40:16 GMT  
 how to throw exceptions from a COM component?
Your component must support ISupportErrorInfo and then just call
AtlReportError from your component.

Dave


Quote:
> 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.



Sat, 08 May 2004 22:24:35 GMT  
 how to throw exceptions from a COM component?
To clarify some of the other responses, you can't "throw" across COM
boundaries.  So, you can't "throw" an error that VB "catches".

However, returning a failure HRESULT triggers VB's error handling.  For
information on how to pass along error information to VB, look at
CComCoClass::Error, and related topics.
"This method sets up the IErrorInfo interface to provide error information
to the client. To call the Error method, your object must implement the
ISupportErrorInfo interface."



Sun, 09 May 2004 00:10:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Exceptions - Throwing Between My Components

2. Throwing com exceptions across process boundaries...

3. throwing exception from COM object's constructor

4. ATL COM DLL :: DllRegisterserver throw exception 0x80029c4a

5. throwing exception from COM and catching it in ASP

6. Throw exception from ATL COM for both VB and VC++ client

7. throwing exception from COM object's constructor

8. Do MTS components support COM Exceptions?

9. Exception handling - how to know which exceptions are thrown

10. COM Component w/o Component Services

11. COM Components to be listed in available Components of Packe wizard

12. property throws Exception in visual designer!

 

 
Powered by phpBB® Forum Software