Error Handling

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi,

I am attempting to write an error handling Function where
it will log any errors encountered into a table.

I am wondering if it is possible to get the Line Number of
where the error occured within code to help me 'iron out'
the underlying problem.

Is this possible?

Cheers,
Steve.
 
Steve said:
Hi,

I am attempting to write an error handling Function where
it will log any errors encountered into a table.

I am wondering if it is possible to get the Line Number of
where the error occured within code to help me 'iron out'
the underlying problem.

Is this possible?

No.

Neither will you automatically get the function (procedure) name where
an error occurs, unless you
* have an error handler in every routine (under consideration)
* explicitly set some variable to the name of the routine
 
Hi Steve,

There is a function named Erl which when called will give the number of the
last numbered line on or before the error occured. For example:

Public Sub TestERL()
On Error GoTo Proc_err
Debug.Print 1
10 Debug.Print 2
Debug.Print 3
30 MsgBox Forms!MyPhantomForm.nocontrol

Proc_exit:
Exit Sub

Proc_err:
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & "LineNum: " &
Erl()
Exit Sub

End Sub

Erl() will return 30 as the line number but if you remove the line number
from the msgbox line, Erl will return 10. I can not find any documentation
on this function but it has existed since Access97 if not earlier.
 
-----Original Message-----


No.

Neither will you automatically get the function (procedure) name where
an error occurs, unless you
* have an error handler in every routine (under consideration)
* explicitly set some variable to the name of the routine

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

.
Bas,

Thanks for the reply. I have placed a call to the
function within each procedure and completed a variable to
pass the 'Source' function.

I am merely attempting to find a way to locate where the
error occured within the procedure.

Thanks anyway,

Steve.
 
Thanks for that Sandra, its a great help.

Cheers,
Steve

-----Original Message-----
Hi Steve,

There is a function named Erl which when called will give the number of the
last numbered line on or before the error occured. For example:

Public Sub TestERL()
On Error GoTo Proc_err
Debug.Print 1
10 Debug.Print 2
Debug.Print 3
30 MsgBox Forms!MyPhantomForm.nocontrol

Proc_exit:
Exit Sub

Proc_err:
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & "LineNum: " &
Erl()
Exit Sub

End Sub

Erl() will return 30 as the line number but if you remove the line number
from the msgbox line, Erl will return 10. I can not find any documentation
on this function but it has existed since Access97 if not earlier.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi,

I am attempting to write an error handling Function where
it will log any errors encountered into a table.

I am wondering if it is possible to get the Line Number of
where the error occured within code to help me 'iron out'
the underlying problem.

Is this possible?

Cheers,
Steve.

.
 
Actually, Further to my previous message. Is there anyway
of doing this without typing the line number in on each
line of code?

I have tested it and get 0 as the line number each
time.....

Cheers,
Steve

-----Original Message-----
Hi Steve,

There is a function named Erl which when called will give the number of the
last numbered line on or before the error occured. For example:

Public Sub TestERL()
On Error GoTo Proc_err
Debug.Print 1
10 Debug.Print 2
Debug.Print 3
30 MsgBox Forms!MyPhantomForm.nocontrol

Proc_exit:
Exit Sub

Proc_err:
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & "LineNum: " &
Erl()
Exit Sub

End Sub

Erl() will return 30 as the line number but if you remove the line number
from the msgbox line, Erl will return 10. I can not find any documentation
on this function but it has existed since Access97 if not earlier.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi,

I am attempting to write an error handling Function where
it will log any errors encountered into a table.

I am wondering if it is possible to get the Line Number of
where the error occured within code to help me 'iron out'
the underlying problem.

Is this possible?

Cheers,
Steve.

.
 
No and Yes - the line number must be present for Erl to return something
other than 0. Yes, there are utilities around that will add the line numbers
for you. I use CodeTools by FMS (www.fmsinc.com). It has a feature that adds
the linenumbers, then another that removes them so that when you roll out to
production, your code is very streamlined. There are probably others out
there or you could write your own if you are feeling adventurous!

I rarely implement code with linenumbers but on occasion, I will if I can't
nail down the problem without them.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Actually, Further to my previous message. Is there anyway
of doing this without typing the line number in on each
line of code?

I have tested it and get 0 as the line number each
time.....

Cheers,
Steve

-----Original Message-----
Hi Steve,

There is a function named Erl which when called will give the number
of the last numbered line on or before the error occured. For
example:

Public Sub TestERL()
On Error GoTo Proc_err
Debug.Print 1
10 Debug.Print 2
Debug.Print 3
30 MsgBox Forms!MyPhantomForm.nocontrol

Proc_exit:
Exit Sub

Proc_err:
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & "LineNum:
" & Erl()
Exit Sub

End Sub

Erl() will return 30 as the line number but if you remove the line
number from the msgbox line, Erl will return 10. I can not find any
documentation on this function but it has existed since Access97 if
not earlier.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi,

I am attempting to write an error handling Function where
it will log any errors encountered into a table.

I am wondering if it is possible to get the Line Number of
where the error occured within code to help me 'iron out'
the underlying problem.

Is this possible?

Cheers,
Steve.

.
 
Steve said:
Bas,

Thanks for the reply. I have placed a call to the
function within each procedure and completed a variable to
pass the 'Source' function.

I am merely attempting to find a way to locate where the
error occured within the procedure.

Thanks anyway,

Steve.

Have I been rude? Apologies then. :-)

I have spent ages looking for a way to log the offending line, but found
nothing. There must be some relation between the text representation of
the code (which you see) and the compiled code (which runs) otherwise
the debugger could never show you the error location; maybe that
requires an API I'm unaware of.
 
Sandra said:
No and Yes - the line number must be present for Erl to return something
other than 0.
I rarely implement code with linenumbers but on occasion, I will if I can't
nail down the problem without them.
Phew, line numbers; that is pretty much back to the Commodore 64! ;-)
 
Bas said:
I have spent ages looking for a way to log the offending line, but found
nothing. There must be some relation between the text representation of
the code (which you see) and the compiled code (which runs) otherwise
the debugger could never show you the error location; maybe that
requires an API I'm unaware of.

Hi Bas,

Give it up - ;-)

Michael Kaplan (Michka) has confirmed that it can't be done. The call stack
is only available in break mode. Here is a link to one of Michka's posts on
this subject:

http://groups.google.com/groups?hl=...q=call+stack+michka+sandra+daigle&sa=N&tab=wg
 
Or Cobol!

To be honest I haven't used line numbers very often but there has been the
occasional time when my other methods tracking down an error didn't work and
finding the line number of the problem line was useful.
 
Back
Top