Solved

Trapping errors from Business Tier DLL

Posted on 2001-06-21
11
327 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 143

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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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 143

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Acccess - Update Field in Table when report is printed 6 47
Spell Check in VB6 13 127
pop out of webbrowser1 control vba6 5 26
Send outlook email from VBS Script 2 45
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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