I don't know how to handle this

G

Guest

I created a COM+ component and I need to pass an event to the client app.
Here is my scenario.

I have this component that checks if a product number is valid

.....................

Public Class ProductChecker

Protected WithEvents myOtherCompoent As new OtherComponent

...............

Public Function IsProductValid(sProdID as string) As Boolean Implements
IProdChecker.IsProductValid

Try

With myOtherCompoent

..ProdID = sProdID
..ValidateProduct

End With

Return True


Catch ex As OtherComponent.Exception

End Try

End Function

End Class


When a client calls this component it returns true if product is valid. This
component basically calls the .ValidateProduct from another .dll
(OtherComponent.dll) but this is the problem. The other .dll
(OtherComponent.dll) raises an exception if the product is invalid and I need
to also pass that exception message back to the client. At the moment I can
catch the exception in Catch ex As OtherComponent.Exception but how do I pass
it to the client. I tried

Catch ex As OtherComponent.Exception

Return ex.message

but I got an error because the function that initiates the error (Public
Function IsProductValid) returns type Boolean. Any ideas?

Basically the component should return True if product is valid of false if
invalid alsong with reason (exceptions returned buy other dll) as well.

Thanks
 
C

Chris Dunaway

Chris said:
it to the client. I tried

Catch ex As OtherComponent.Exception

Return ex.message

If you're able to catch the exception from the other .dll, then just
re-throw it or throw a new exception and set its InnerException
property to the exception you originally caught:

Try
'blah
Catch ex As OtherComponent.Exception
Throw 'Throw by itself, just re-throws the same
exception
End Try

OR

Try
'Blah
Catch ex As OtherComponent.Exception
Throw New MyCustomException(ex) 'throw a different exception and
pass ex
End Try

Just a thought
 
G

Guest

Hi,
Thanks for the info. How do I catch this in the com+ client? Do you know
where I can find additional info.

Thanks
 
G

Guest

Thanks. It worked!

Chris Dunaway said:
If you're able to catch the exception from the other .dll, then just
re-throw it or throw a new exception and set its InnerException
property to the exception you originally caught:

Try
'blah
Catch ex As OtherComponent.Exception
Throw 'Throw by itself, just re-throws the same
exception
End Try

OR

Try
'Blah
Catch ex As OtherComponent.Exception
Throw New MyCustomException(ex) 'throw a different exception and
pass ex
End Try

Just a thought
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top