?
Solved

Error handler errors

Posted on 2006-07-10
20
Medium Priority
?
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +3
20 Comments
 
LVL 66

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Accepted Solution

by:
justchat_1 earned 252 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 248 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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