Solved

Error handler errors

Posted on 2006-07-10
20
377 Views
Last Modified: 2008-02-01
I have an occassional issue with my error handler and not sure why it is happening and was hoping to get some thoughts.

Here is a example of one of the procedures where the error happens

----
Private Function OpenPublisherConnection() As ADODB.Connection
1   On Error GoTo ERROR_HANDLE
2   Set OpenPublisherConnection = New ADODB.Connection
3   If CheckForServer(rsRepConfig!PublisherAddress) Then
4       If IsNumeric(GetSetting("MDBS", "Options", "SQLConnectionTimeout", "")) Then
5           OpenPublisherConnection.ConnectionTimeout = GetSetting("MDBS", "Options", "SQLConnectionTimeout", 30)
        End If
6       If IsNumeric(GetSetting("MDBS", "Options", "SQLCommandTimeout", "")) Then
7           OpenPublisherConnection.CommandTimeout = GetSetting("MDBS", "Options", "SQLCommandTimeout", 30)
        End If
8       OpenPublisherConnection.Open "Driver=SQL Server;" & _
            "SERVER=" & rsRepConfig!PublisherAddress & ";" & _
                "UID=" & DecryptString(Trim(rsRepConfig!PublisherLogin)) & ";" & _
                    "PWD=" & DecryptString(Trim(rsRepConfig!PublisherPassword)) & ";" & _
                        "DATABASE=" & rsRepConfig!PublisherDatabase
    End If
    Exit Function
ERROR_HANDLE:
9      CentralErrorHandler "frmCallMatco.OpenPublisherConnection"
    End If

End Function
--
CentralErrorHandler just displays the error message to the user, bypassing the displaying of some messages and then enters the error into a table to be transmitted to a central server for review.

The issue that I am seeing is occasionally I will get entries for this and other procedures that have a 0 error number and a 0 error line number.  Anyone have any ideas why these would kick to my error handler even though there is "technically" no error?

This is more of an annoyance then anything as I have added this to list of error numbers not to show to the user.

Thanks in advance for any assistance.
0
Comment
Question by:KOCUBA
  • 5
  • 5
  • 2
  • +3
20 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17075566
> Anyone have any ideas why these would kick to my error handler even though there is "technically" no error?
Probably there are places in your code that call it before Exit Sub or Exit Function, which means the code executes but err.number = 0

You can put this at the top of your error handler:

If err.Number = 0 then
   Exit Function
End IF
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17075568
The problem is that when calling a procedure, the error variables get cleared.
you have to pass the values of Err.Number, Err.Source, Err.Description etc to the procedure CentralErrorHandler.
0
 

Author Comment

by:KOCUBA
ID: 17075857
jimhorn,  As you can see from this procedure and all off the others that I have pop up with this issue they all contain the Exit Sub(or Function)  so that would not be the case.  

angellIII,  This works for handling errors thoughout the whole application this way so I do not need to pass those values.  

Just for some reason it is getting to the error handler withoout having an error.  I'm just wondering why.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 9

Accepted Solution

by:
justchat_1 earned 63 total points
ID: 17075912
If there is an error with the ADODB.Connection then that will go into an error state but because the regular vb functions didnt cause an error the error code is still 0...
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17075959
what's the GetLastError tell you if err is 0
0
 

Author Comment

by:KOCUBA
ID: 17075989
justchat_1,  Sounds possible but I do get error mesages for the ADODB.Connection.  Also I have procedures that don't reference that and still have these entries.

0
 

Author Comment

by:KOCUBA
ID: 17075998
EDDYKT,  Don't use that property currently but I can give it a try.
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17076003
For more info on ADODB errors check this out:
http://support.sas.com/rnd/eai/oledb/app_error_objects.htm

it might be your problem...
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17076029
It could be a combination of my suggestion and angelIII's suggestion... Many objects trap errors internally and will raise an error but you have to reference them not err.number to find out what it is...  It could also be error handlers that are accidently fired...
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 62 total points
ID: 17076047
May be you shall also use err.LastDllError

Err.Number is always 0 because VB does not trap Win32 API errors. The LastDllError property, however, seems to work.


http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_12018083.html
0
 
LVL 18

Expert Comment

by:JR2003
ID: 17086260
angelIII is right when he says that the problem is that when calling a procedure, the error variables get cleared.
you have to pass the values of Err.Number, Err.Source, Err.Description etc to the procedure CentralErrorHandler
An alternative is to have in each error-trap  code that sets some global variables with the error code etc.

If you get mztools you can put in some standard error trapping and add it to each procedure with the click of a button.
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17086948
yea didnt see that before...good call
0
 

Author Comment

by:KOCUBA
ID: 17090007
JR2003,  As I already stated..  This is not true because this is how it works thru out the whole application and I get correct error logs all the time.  The only possiblity with this thought is that there is some error that is happening and not getting logged then resetting the error variable.  But then the question is why?

And I do have and use mztools
0
 
LVL 18

Expert Comment

by:JR2003
ID: 17092493
I'm sure it never used to do that when I used vb6?
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17093543
I could have been right then:
"It could be a combination of my suggestion and angelIII's suggestion..."
0
 

Author Comment

by:KOCUBA
ID: 17341877
Thta's fine.  None of them are really correct but thanks for trying.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
How does CurrentUser work? 10 38
using web browser with BING 40 130
How to make an ADE file by code? 11 94
Publisher:   Unknown     VB.exe Application 1 27
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 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