Passing exceptions from a Dll back to the calling application.

D

dave m

I'm creating a class library (dll) and am confused as how to pass any
information, should any exceptions occur, back to the calling application.
Such as:

Try
x = 3 / 0 ' divide by 0 error
Catch ex as Exception
'(how do I pass ex info back to calling app?)
End Try

(In VB6 I would have used " Err.Raise Err.Number, Err.Source,
Err.Description".)

Any advice would be greatly appreciated.


Thanks,

Dave M.
 
H

Herfried K. Wagner [MVP]

dave m said:
I'm creating a class library (dll) and am confused as how to pass any
information, should any exceptions occur, back to the calling application.
Such as:

Try
x = 3 / 0 ' divide by 0 error
Catch ex as Exception
'(how do I pass ex info back to calling app?)
End Try

(In VB6 I would have used " Err.Raise Err.Number, Err.Source,
Err.Description".)

\\\
....
Catch
Throw
End Try
///
 
M

Michel Posseth [MCP]

well i do not see the point of catching the error at all the dll if you
want it to bubbel up to the caller you could just errors are always chained
just as in VB6
so if you write a handler in a top level of the chain the error will be
catched there with much less overhead and more information about the origin


Sub inDll ()
x = 3 / 0 ' divide by 0 error
end sub


sub incaller ()
Try
foo.inDll ()
Catch ex as Exception
'do your handling stuff here
End Try
end sub

You could also choose not to implement a handler in your calling routine in
this case your program will crash with this raised exception

I have seen lots of code with catching and rethrowing implemented first i
thought i was the one missing something ( and have asked what other people
think in this newsgroup ) but in the end it is most of the times a waste
of resources with a less descriptive error message

In my opinion rethrowing exceptions should only be done if you need to clean
up some stuff and then pass the error on to a higher level


regards

Michel
 
M

Michel Posseth [MCP]

Yuck let me rephrase this :) somehow it leaved my brain but didn`t made it
to my message the right way

well i do not see the point of catching the error at all in the dll if
you
want it to bubbel up to the caller, you could just let the chaining
mechanism handle this , errors are always chained
just as in VB6,
so if you write a handler in a top level of the chain the error will be
catched there with much less overhead and more information about the origin
 

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