Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

error handler with error line number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TomS - 27 Jul 2005 23:22 GMT
Hi,
I have a function in Word-VBA with error handler writing some info to log
file. There are strange errors occuring from time to time which I can't
trace. It would be very helpful for me to have information about line in
which error has occured. Is this possible?

For example:

sub foo()
   on error goto ErrorHandler
   'some code here

   exit sub
ErrorHandler:
   ErrNumber = Err.Number
   ErrDesc = Err.Description
   LineNumber = ???
   AddToLog "ERROR:foo:" & LineNumber & ":" & ErrNumber & " " & ErrDesc
   'resume or resume next - doesn't matter now...
end sub

I don't want to examine my specific function, I just would like to now in
general, if it is possible to read line number in which last error
occured.

Regards,
Tomek
Jezebel - 28 Jul 2005 00:02 GMT
VB still supports the erl instruction which reports the line number at which
the error occurred, but only if you use old-fashioned line numbering --

sub foo()

10    on error goto ErrorHandler
20   'some code here
30

   exit sub
ErrorHandler:
   ErrNumber = Err.Number
   ErrDesc = Err.Description

   LineNumber = erl            <<=======

   AddToLog "ERROR:foo:" & LineNumber & ":" & ErrNumber & " " & ErrDesc
   'resume or resume next - doesn't matter now...

Note that you don't have to number *every* line. erl reports the last line
number up to and including the line that caused the error, so it might be
sufficient for debugging to insert one number for each 'section' of code.

> Hi,
> I have a function in Word-VBA with error handler writing some info to log
[quoted text clipped - 23 lines]
> Regards,
> Tomek
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.