Errors in DLL

Hi.

'this is my Dll
Dim oTrans as New Trans

'i use his method, but ensue error
oTrans.Method

'I need know Error number of this error
MsgBox Err.Number
mikibenekAsked:
Who is Participating?
 
josevillarConnect With a Mentor Commented:
to mikibenek

If you want to raise an error you
have to add "vbObjectError" to your code

Public Function Method(ByVal cErr As string)
    If cErr = "" Then Err.Raise vbObjectError + 5
     
End Function
0
 
Éric MoreauSenior .Net ConsultantCommented:
What is the code in your DLL? Do you handle error in there?

Have you tried "err.Raise err.number" in your method?
0
 
josevillarCommented:
I'm not sure if I understand your problem.

You need an "On Error Goto" clause in the class method.
Once an error fires you can retrieve it in a class property named ErrNumber.

Dim oTrans as New Trans

oTrans.Method

msgbox oTrans.ErrNumber
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Éric MoreauSenior .Net ConsultantCommented:
josevillar brings a good point!

Your client code must look like this:

Sub Something()
'this is my Dll
Dim oTrans as New Trans

on error goto eh

'i use his method, but ensue error
oTrans.Method

exit sub

eh:
'I need know Error number of this error
MsgBox Err.Number

End Sub
0
 
mikibenekAuthor Commented:
To emoreau:
I have it so, but oTrans return err.number = 0.
0
 
mikibenekAuthor Commented:
To emoreau:
I have it so, but oTrans return err.number = 0.
0
 
Éric MoreauSenior .Net ConsultantCommented:
What is the code in your Method?
0
 
mikibenekAuthor Commented:
To emoreau:
I have it so, but oTrans return err.number = 0.
0
 
mikibenekAuthor Commented:
To emoreau:
I have it so, but oTrans return err.number = 0.
0
 
mikibenekAuthor Commented:
Public Function Method(ByVal cErr As String)
    If cErr = "" Then Err.Raise 5
   
End Function
0
 
Éric MoreauSenior .Net ConsultantCommented:
Right-click in the code editor, choose toggle and choose break on unhandled errors.
0
 
Éric MoreauSenior .Net ConsultantCommented:
vbObjectError has nothing to do with the fact that the error will be handled by the client app or not!
0
 
mikibenekAuthor Commented:
To emoreau:
Sorry, I know it. I solved my problem alone.
0
 
Éric MoreauSenior .Net ConsultantCommented:
By curiosity, how did you solve it?
0
 
mikibenekAuthor Commented:
Public Function Method(ByVal cErr As string)
On Error GoTo Error

  If cErr = "" Then GoTo Error
   Exit Function

Error:      
  Err.Raise vbObjectError + number
End Function
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.