Solved

Trapping errors from Business Tier DLL

Posted on 2001-06-21
11
321 Views
Last Modified: 2010-05-02
I develop a three tiers application in VB6, client-server architecture.
The User interface tier is a VB6 EXE project. The Business tier is a VB6 Active X COM project (DLL) that has some classes.
The data are introduced by a VB form of User interface tier, but is validated in Business tier?s property functions.
When a data isn?t OK (wrong data), I have to write a message on the screen and retry the data input flow in the User interface tier input procedure.
My problem is:
How can Business object tier procedure to tell User interface tier procedure that there are an error (and it have to retry the data input).
I have try to use err.Raise in Business tier procedure, but User interface tier procedure isn?t interrupted by an error:
On Error goto err:
     Object.member=value     ?call the property function of member of object.
     ?The property contains err.Raise
     Msgbox ?is ok?
     Exit sub
Err:
     Msgbox ?I was interrupted by an error?
     End sub
I see ?is ok?.
Is this unpleasant situation related to the following sentences from MSDN Library Visual Studio 6.0 help: ?System errors during calls to Windows DLL do not raise exceptions and cannot by trapped with Visual Basic Error trapping? ?
How can I trap validation errors from Business object tier procedure?

0
Comment
Question by:redundguy
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6213912
A simple Err.Raise will not be enough, i must contain at least a non-zero error number:
Err.Raise 994349
Additionally, you can supply the Description, source aso

The info you read from the Windows DLL is different: the code in there will not raise exceptions, but give you return codes, which indicate if the code has executed successfully or not.

Cheers
0
 
LVL 1

Expert Comment

by:barendb
ID: 6213913
redundguy,

You'll have to use a method in the DLL part to pass the data to the DLL, validate it and return a value to the EXE if data was accepted or not, you can even return a UDT with the error value (if any) and the value that returned the error.

Hope this helps.

Barend
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6213914
Should work properly IMHO.

Err.Raise vbObjectError + 512

Regards,
CJ

(ps. if you write something in word anc copy / paste it, the single quote will be changed the a question mark, as you can see in your question :-)..)
0
 
LVL 15

Expert Comment

by:ameba
ID: 6213977
Last 10 Grades Given:  A B C    :-(

Before raising the error, *always* include "On Error GoTo 0" line.

' this DOES NOT work
Public Property Let Phone1(ByVal NewValue As String)
    On Error Resume Next
    If NewValue = "" Then
        Err.Raise 5
    End If
End Property

' this works OK
Public Property Let Phone2(ByVal NewValue As String)
    If NewValue = "" Then
        On Error GoTo 0
        Err.Raise 5
    End If
End Property

Note: Do not accept my comment 'as answer' if it is not for A grade!
0
 
LVL 1

Author Comment

by:redundguy
ID: 6214055
Angellll, I have used the number. (1001)
CJ_S, it doesn?t work
Ameba, it doesn?t work.
 
Sorry, I was incorrect. I saw the message
 ?Run time error 1000? when I expected to see:
?I was interrupted by an error?.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:simonbennett
ID: 6214058
Everyone is right, it should work, unless you are jumping out of scope within your error handler. Only alternative is to raise an event in the server e.g.

Public Event ValidationFailed(byval theError as Error)

...and then trap it in the client

Public Withevents MyObject

Public Sub MyObject_ValidationFailed(byval theError as Error)
   err.raise theError.Number ' and the other error properties!

end sub

HTH and good luck

Simon
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6214069
In your business-tier DLL, you need to have 'unattended execution' checked in the project properties dialog box.
This will ensure that any errors raised get sent back to the calling DLL.

If you still can't get it to work, post the code in your property Let procedure up and we can have a look at that.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6214072
Please show how you are raising the error, and the error handling in the function where you raise the error. Then please also show how the error handling is done at the client. That will give us a better view of what you are currently doing.

regards,
CJ
0
 
LVL 1

Author Comment

by:redundguy
ID: 6214182
The error is raised in BO tier Property procedure with:
   err.Raise 1000.
The error is handled only in UI tier procedure with the code I have already shown.
Thanks to all!
I'm sory, I have to go out. We'll see tomorow!
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 133 total points
ID: 6214278
I think the problem is a VB IDE setting:
Check out the "Break on..." settings in your options,
where you can set to one of these:
* Break on all errors (which is set, i guess)
* Break in Class module
* Break on unhandled errors

Note that the last one behaves as if you compiled the application....

Cheers
0
 
LVL 1

Author Comment

by:redundguy
ID: 6223993
Thanks to all
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now