Visual Basic 6 question - Error Handling

Status
Not open for further replies.

bw

Ars Tribunus Angusticlavius
7,308
That's always been an issue for me. The way I do it is I put in a break when an error occurs then a I can step through the code after the error. The error is usually the line of code right before the item where you resume.

To step through the code, hit F8. Note: I'm using Microsoft's VB6. If you're not using that, i'm not sure if the F8 key works to step through the code line by line.
 

ske_ez

Seniorius Lurkius
15
What kind of error is it?..logical, compilation, etc. If it involves variables you set a watch, set it for a value that creates the error and it will stop at the point when it happens. Also make sure in the options that you have set Break on all Errors option. I don't know of any tool that will do this for you. Do you have any classes that get called? You can also have VB stop of those errors as well and in the immediate window you can see the last err.number/description call. I hope this helps, if not...well, lets hope its something simple.
 

bw

Ars Tribunus Angusticlavius
7,308
What kind of errors? Does the application crash when it reaches an error or is it the final output that looks all wrong?

I usually have a lines on code in my function or sub that let's me debug the code.

code:<HR>
Code:
Sub Main()<P>On Error GoTo Err_Handler<P> 'Your Code Here<P>
Exit Sub<P>Err_Handler:<P>MsgBox "Error:  " & Err.Number & " - " & Err.Description
Resume Next
End Sub

When the message box comes up with an error, break the code and step through it. Read my previous post for the rest.
 

Saidin

Seniorius Lurkius
24
Ok here's the exact problem....

I have code that is running live as we speak. When ever an error occurs in the program, it e-mails me the info about the error. i.e Error number, error description.

Unfourtunetly, that isn't enough info to go on. If I knew what line the error occured on I could debug it.

So i was asking of there is a way to figure out what line the error occured on..

Thanks
 

Deniro

Ars Scholae Palatinae
711
Subscriptor++
I used a tool at a client site to debug some run-time VB errors. The product was a CD from Numega with DevPartner Studio 6.5 on it. One of the tools (Smartcheck I think) would catch run-time errors. Here is a link to it.
You haven't said yet if you will be able to get to the code to make changes. If you use a 3rd party tool to find out the definite error, are you able to make code changes, or do you think it might not be the code?
I don't know how easy or quick it would be to get a trial version or something of this particular product. As others have mentioned, it would be easiest to make a change to the code to help you narrow down the problem area of code.
 

bw

Ars Tribunus Angusticlavius
7,308
Originally posted by Saidin:
Ok here's the exact problem....

I have code that is running live as we speak. When ever an error occurs in the program, it e-mails me the info about the error. i.e Error number, error description.

Unfourtunetly, that isn't enough info to go on. If I knew what line the error occured on I could debug it.

So i was asking of there is a way to figure out what line the error occured on..

Thanks

The error might not be in the code itself. I'll assume you inherited this code from some past employee.

Depending on the error code/description, it could be that it can't connect to a database, it can't find a file it's looking for, or any other "missing" items.

Can you give us examples of the error??
 

zolakk

Ars Scholae Palatinae
909
This is exactly why I wrote a program to put line numbers in my code before I make a distro build of a program. If you use line numbers, the system variable(?) 'Erl' stores the error line number. Dump that to a file (or a database) as well as the sub that generated the error, the date/time/program version number and possibly a variable/textbox dump and the actual error text in your error handling routines (you do handle errors in all subs/functions, right?) and you're good to go... that there cut my debugging time in at least half easily. I'll look into seeing if I can post a compiled version of this program (uses command line options to specify source dir and a few other options) as I wrote it at/for my work and from what I read of their policy "All my code belong to them" (sorry, could'nt resist :p) and giving it away could be a Bad Thing.

Edit: Sorry about bringing up such an old thread, but I find a lot of people asking me this
 
Status
Not open for further replies.