Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / October 2003



Tip: Looking for answers? Try searching our database.

Err.Raise

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
João Pereira - 25 Oct 2003 18:02 GMT
Can anybody explain me how can i use Err.Raise in a DLL,
and the err is passed to the client? In all the MS's doc
that i read all say that if you raise an err in a
component module that doesnt have an 'on error' then the
error is passed to the cliente. How????

Thanks
Bo - 25 Oct 2003 23:24 GMT
Well, just like thay have said.  If no error hander is active, the error is
raised up to the next level.

So,  if you want to raise an error, then you have to turn off your current
error hander(s) if any exist.
The catch is, you might be down inside a sub/function or a nested
sub/function, and turning of the error handler there wont be enough.

You must have no active error hander between the routine that raises the
error, and the client.

Illustration :

   Client loads a DLL
   Client invokes one of the DLLs methods, say:  CalcWeeksWages
   CalcWeeksWages turns on an error hander before invoking a series of
lower level subs/functions.
   Lower level sub/function breaks, experiences an error he cant resolve,
and raises a new error to CalcWeeksWages
   The Error handler in CalcWeeksWages examines the conditions and decides
he cannot resolve it, and must raise an Error to the client
       CalcWeeksWages must now de-activate his active error handler, and
then issue a Raise.Err
       He will not handle this new error, because he had just de-activated
his own error handler.
   So... the error handler in the client will be invoked.

This creates a wee bit of a warped design, because good design dictates that
every routine capable of causing an error should have a handler.
Likewise, so should any routine that calls another routine which -could-
experience an unhandled error.   So, on that basis, all your routines should
probably have an error handler.  But the highest level one must be able to
deactive his handler and created an unhandled error, if you want to make use
of Raise Error to call the client.  Likewise, your lower level routines must
either do the same thing, that is : deactive their error hander,
conditionally, and raise an error to their caller, OR, return results that
reflect an un-resolved error.  The net result is that each sub/function will
have 2 exit points, one for success and Handled errors, and one for
unhandled errors.

HTH

> Can anybody explain me how can i use Err.Raise in a DLL,
> and the err is passed to the client? In all the MS's doc
[quoted text clipped - 3 lines]
>
> Thanks
João Pereira - 26 Oct 2003 09:24 GMT
The problem is that when i call a DLL function from the cliente who has a On
Error. Ex.:

sub DoAnith()
   dim clOne as SomeDLL

   On Error Goto ErrorHand

   Set clOne = New SomeDLL
   clOne.SomeSub
Exit Sub
ErroHand:
   msgbox err & " - " & err.description
exit sub

DLL code:

Public Sub SomeSub()
   ....
   Err.Raise vbObjectError + 1, Me.Name, "Error"
end sub

The problem is that i get a run-time error from the DLL sub SomeSub, that
is: the error is not passed to the client function... WHY?

Thank you for your time

> Well, just like thay have said.  If no error hander is active, the error is
> raised up to the next level.
[quoted text clipped - 45 lines]
> >
> > Thanks
Eduardo A. Morcillo [MS MVP] - 26 Oct 2003 16:02 GMT
> The problem is that i get a run-time error from the DLL sub SomeSub,
> that is: the error is not passed to the client function... WHY?

Open the Options Dialog, select the General tab and set "Error Trapping" to
"Break on Unhandled Errors".

Signature

Eduardo A. Morcillo [MS MVP]
http://www.mvps.org/emorcillo

João Pereira - 26 Oct 2003 17:02 GMT
Thank you VERY Much... You made me win the day...

> > The problem is that i get a run-time error from the DLL sub SomeSub,
> > that is: the error is not passed to the client function... WHY?
>
> Open the Options Dialog, select the General tab and set "Error Trapping" to
> "Break on Unhandled Errors".
Diederik - 31 Oct 2003 21:01 GMT
> Can anybody explain me how can i use Err.Raise in a DLL,
> and the err is passed to the client? In all the MS's doc
[quoted text clipped - 3 lines]
>
> Thanks

Just use it.
If an error occurs in a function which doesn't have an error handling
routine then the error will be propagated upwards the chain until it
finds one.
So if component A calls component B's method X and some error occurs in
that method and it doesn't have a error handler, the error will be
passed back to component A. If component A has an error handling
routine the error will be handled there.
If it can't find any error handling function, your program will crash.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.