Solved

Error handler errors

Posted on 2006-07-10
20
368 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 142

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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 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

21 Experts available now in Live!

Get 1:1 Help Now