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".
> 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.