473,513 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to capture the procedure name in error trapping.

137 New Member
Currently I've expanded on the code provided by Rob Henderson in the download file here: http://www.vb123.com/toolshed/04_acc...orhandling.htm

This code allows you to provide detailed error trapping to the user. It will currently print out the error number, description, and form that created the error.
As well as this, the code will allow you to automatically record these errors in a table.

I'm trying to also find a way to expand on just being told which form has created the error - I would like a way to record the procedure that has called the error.

My problem is actually calling the error function from the procedures. Currently the error code looks like this:

Expand|Select|Wrap|Line Numbers
  1. 'Error handling - see mdlError module.
  2. DeleteTest_Click_Err:
  3.     Call ErrorLog(Err.Description, Err.Number, Me.Name)
  4.     Resume DeleteTest_Click_Exit
What's missing is the procedure reference, it should say something like:

Expand|Select|Wrap|Line Numbers
  1. 'Error handling - see mdlError module.
  2. DeleteTest_Click_Err:
  3.     Call ErrorLog(Err.Description, Err.Number, Me.Name, Me.ProcedureName)
  4.     Resume DeleteTest_Click_Exit
Obviously, "Me.ProcedureName doesn't exist, but what I'm missing is the right call to capture the procedure name. Does such a thing exist? Is there a simple implementation for this? I've done all the code in the mdlError module to handle the procedure name, it's just a way of getting the name in the first place!
EDIT: I was looking for a generic way to do this with a "one fits all" solution, as I don't really fancy going through 500+ procedures to manually hard code each individual procedure name into the error coding, when find + replace could do this automatically.

Here's hoping this is another obviously simple question! :)

Thanks in advance.
May 18 '11 #1
13 5574
Lysander
344 Recognized Expert Contributor
Hi Adam,

I have done a search on the net and the answer to this question seems to be no, no simple way, you have to manipulate the stack! I did find product that does this for you, called vbWatchdog, which costs £45.

There is another solution. I wrote an article here that implents global error handling in all procedure automatically. I never write any error handling now at all. When I have finished the days coding, I run my routine and it puts all the error handling in.

Now, my point is that my code, at the time of generating the error handling, knows the name of the procedure it is modifying, and so you could modify my code to add the prodcedure name to your own error handling.

Now, how do I provide a link to my article?
It's called
"Automatic Error Handling in Access"
http://bytes.com/topic/access/insigh...andling-access
May 18 '11 #2
NeoPa
32,558 Recognized Expert Moderator MVP
Unfortunately the Err object seems to have no reference to the line number that the error occurred on. Otherwise you could reference Me.Module.ProcOfLine(<ErrLine>, lngProcType) where lngProcType is a Long which takes a returned value of the type of procedure returned.

This technique may still prove useful but I see no way to tie it directly to the error line I'm afraid. Even if the concept of the <Current Line> were available anywhere this could be used, as the error handler typically runs within the same procedure. Nothing found there either I'm afraid.
May 18 '11 #3
Adam Tippelt
137 New Member
My search of the internet came up with the answer of no as well, but I figured I'd ask the experts here as well.
This functionality is just one of those "little extras" that are nice to have, but I certainly don't want to pay £45 for it!

I've heard of automatic error coding before, just never really looked into it. I had a quick skim of your article and it looks rather informative, so i'll have a closer read of that and see if that can help.

Thanks Lysander.

Adam.
May 18 '11 #4
Adam Tippelt
137 New Member
Yes NeoPa, it's a shame that no line numbering exists as a standard for VBA (without using mods), as it would be useful just when writing code...
May 18 '11 #5
Lysander
344 Recognized Expert Contributor
Adam, I could not work without the error handling code I developed. Well, I could, but it would take ages and probably loads of typo mistakes. What I posted here was a very basic error handler, but it can be enhanced for all sorts of conditions.

If you think it could help you, I would be more than happy to enhance it for you, in my spare time.

One thing is missing from that system, and that is a bit of code to strip out all existing error handling so that it could be replaced with the new one. Something I should work on one day:)
May 18 '11 #6
NeoPa
32,558 Recognized Expert Moderator MVP
I have to say that it seems a rather strange omission from the Err object. Having said that, I see too many instances of members saying Access or Microsoft have missed the obvious when they are simply aware of too little to judge, not to have a suspicion that this is the case here for me. A fuller understanding often throws new light on matters. In this case I suspect that, as Access projects can be run without the original code in text form even being available, it may be quite inappropriate to provide such information. I can't know of course.
May 18 '11 #7
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I have also myself found it a bit odd, seing as access obviously knows where the error occured (otherwise you couldn't do a Resume in your error handler)

I use this code myself.
Expand|Select|Wrap|Line Numbers
  1. Public Sub doStdErrMsg(Optional strProcName As String, Optional strExtra As String)
  2. '*******************************************************************
  3. ' Purpose:   To simplyfy the code for handling unhandled errors
  4. '            I.e. the errors that are not expected.
  5. '            This simply gives an easy and consistent msgbox in
  6. '            case of errors
  7. '
  8. ' Requires:  The strProjectName constant must be defined
  9. '
  10. ' Input:     [strProcName]: The Name of the function in which the
  11. '                           error has occured
  12. '
  13. ' Output:    A msgbox informing user of error
  14. '*******************************************************************
  15.  
  16.     'Compose message
  17.         Dim strMsg As String
  18.         Dim strTitle As String
  19.         strMsg = "An unexpected error [" & Err.Number & "] has occured"
  20.  
  21.     'If proc name was supplied, include it in msg and titel
  22.         If strProcName & "" <> "" Then
  23.             strMsg = strMsg & " inside '" & strProcName & "'."
  24.             strTitle = strProjectName & ": Error in " & strProcName
  25.             Else
  26.             strTitle = strProjectName & " error"
  27.         End If
  28.  
  29.     'Add description to error message
  30.         strMsg = strMsg & vbNewLine & Err.Description
  31.  
  32.     'If extra is provided add it
  33.         If strExtra & "" <> "" Then
  34.             strMsg = strMsg & vbNewLine & strExtra
  35.         End If
  36.     'Post it
  37.         MsgBox strMsg, vbOKOnly + vbExclamation, strTitle
  38. End Sub
Making my error handling look something like this:
Expand|Select|Wrap|Line Numbers
  1. Err_Handler:
  2.   If Err.Number=71 then
  3.     'Do something
  4.   elseIF Err.Number=91
  5.     'Do somerhing else
  6.   Else
  7.     DoStdErrMsg Me.Name & "_Unload"
  8.     Goto Exit_Sub
  9.   End if
Basicly this means that if an unexpected error occurs (One that I haven't predicted) I can handle it somewhat gracefully without writing verbose code.
May 19 '11 #8
Adam Tippelt
137 New Member
@Lysander: You're probably right - it took me hours to add in all the error trapping - think I added in around 2000 lines for trapping alone.

@NeoPa: One man's madness is another man's method - I'm sure Microsoft have their reasons for not including this obvious functionality...it's just annoying that they haven't...

@Smiley: You've referred strProcName as though you can capture the procedure name that caused the error, yet I don't see how you would obtain that detail in your code, or where it's actually assigned as the strProcName value?

Perhaps I am misreading what you've put, but your code looks similar to what I'm using and when I tried adding a strProcName variable I couldn't assign a value.

------------------

It would appear that the simple answer I was after doesn't exist, which is annoying because I now have an error occurring that hides behind a handled error when I tell it to break on all error...

Ah well - I shall persevere!

Thanks all.
May 19 '11 #9
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Adam Tippelt:
@Smiley: You've referred strProcName as though you can capture the procedure name that caused the error, yet I don't see how you would obtain that detail in your code, or where it's actually assigned as the strProcName value?
strProcName is not something I obtain automatically I am afraid. Its an argument I pass as the example shows.

The main purpose is that I dont have to write a msgbox command each time, with title and the works, but simply write a short message in doStdErrMsg.
May 19 '11 #10
NeoPa
32,558 Recognized Expert Moderator MVP
Ironically enough, I find the most helpful step while debugging is to disable any breaking in the code. This can most easily be done by setting the option to 'Break on all errors'. That way, the line that caused the code to crash is highlighted and the full standard error details are shown.

Released code should probably be run under 'Break in class modules'.

PS. Notice Smiley's second block of code. Line #7 calls the procedure and passes a value that is specific to where it is called from. Other calls will pass their own specific values, but that example is clearly from the form's Load event procedure. I'm afraid it doesn't do everything you want, but it can be a basis for making what you want easier to achieve.
May 19 '11 #11
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I know what you mean NeoPa, allthough I use a slightly different approach. I have a public boolean, bDebugMode, and whenever I need to debug something I set it to true using the Immediate Pane.

When I enable error handling I use:
Expand|Select|Wrap|Line Numbers
  1. If Not bDebugMode then On Error Goto Err_Handler
Your approach does the same basicly.
May 19 '11 #12
NeoPa
32,558 Recognized Expert Moderator MVP
Interesting comment. I suppose such a sub-discussion can be considered a relevant part of the thread. In reality, I tend to comment out the line in a particular procedure if I need to disable error chacking for it, but another approach, similar to yours Smiley, would be to use a conditional compiler constant and to check that within the code stream. This can effect many blocks of code, and be enabled/disabled with a single comment character.

An illustrative example follows :

At the top of the module
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4. #Const conDebug = True     'Only when the project is still in development mode.
Wherever you want code to exist only when in Debug mode
Expand|Select|Wrap|Line Numbers
  1. #If conDebug Then
  2.     On Error GoTo Err_CurrentProcName
  3. #End If
Although I don't generally use this concept for this specific purpose, I use it quite heavily otherwise. In spreadsheets I only protect worksheets in the released project for instance.
May 19 '11 #13
Adam Tippelt
137 New Member
Some of it sounds familiar to what I have been doing to get round things like handled errors in debug mode, so at least I'm doing some of the right things!

Thanks for all the information - can never know enough. :)
May 27 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3249
by: Tom Petersen | last post by:
I am trying figure this out, I am using the example from aspfaq dot com <% If not objRS.EOF then DO WHILE NOT objRS.EOF %> <p align="left"><font face="Arial" size="1">Posted by <%= objRS("name") %> on <%= objRS("date") %> at <%= objRS("time") %></font></td> <%
6
4715
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
3
6863
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records from rsSource into rsDest - if it finds a key violation then it deletes the current record from rsDest and adds the new record from rsSource. This...
3
2728
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command that I can use instead? Cheers Nicolaas
13
4436
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently runs into problems on the system where it will actually be used, and since I used so little error-trapping it dies very ungracefully. I will of...
2
3859
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become visible so the document can be printed and/or modified. This all takes place within one form, in which the Word.Application and Word.Document objects...
0
1500
by: JohnJohnUSA | last post by:
I ran the following program to retrieve entries from the windows registry on Windows XP: import win32api, win32con aReg = win32api.RegConnectRegistry(None, win32con.HKEY_CURRENT_USER) aKey = win32api.RegOpenKeyEx(aReg, r"Software\Microsoft\Internet Explorer\PageSetup") for i in range(100):
9
2094
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR | E_PARSE); set_error_handler("SendErrorReport"); function SendErrorReport($errorNumber, $errorMessage, $errorFile, $errorLine, $vars) {
4
7586
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to an excel spreadsheet. There are two tables. One is a list of general contacts, and the other is a list of clubs. The clubs contain members who...
0
1052
kirubagari
by: kirubagari | last post by:
Dear Expert, I need help where i write the code in pro*c and using putty application to convert the file into .c file.I have concern here.After the compilation,i get the .c file.I want to put error trapping message . The logic as below The exact value as below
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.