|
-
Sep 4th, 2002, 09:50 AM
#1
Thread Starter
Lively Member
Error hand
I want to have a single error hand for the whole application
there are about 6 to 7 forms in it
any error accurres , i want to type the information into a log file and should unload the the current form
where should i write the code
my applications loads form sub main()
Please hepl urgent
with Regards
sameer Mulgaonkar

-
Sep 4th, 2002, 09:58 AM
#2
-= B u g S l a y e r =-
no easy way I think,
in your form, something like this :
VB Code:
Private Sub Command1_Click()
On Error GoTo xit
'code
'code
'code
Exit Sub
xit:
LogIt Me.Name & " -> " & "Command1_Click()" & "Err: " & Err.Number & " -> " & Err.Description
End Sub
Private Sub Form_Load()
On Error GoTo xit
'code
'code
'code
Exit Sub
xit:
LogIt Me.Name & " -> " & "Form_Load()" & "Err: " & Err.Number & " -> " & Err.Description
End Sub
in a module
VB Code:
Option Explicit
Public Function LogIt(sInfoToLog As String, Optional sFileName As String)
Dim ff As Integer
If sFileName = "" Then sFileName = App.Path & "\" & App.EXEName & ".LOG"
ff = FreeFile
Open sFileName For Append As ff
Print #ff, sInfoToLog
Close ff
End Function
tidious work
-
Sep 4th, 2002, 10:14 AM
#3
Thread Starter
Lively Member
So for every procedure in the form i have the write the code
is that so?
that it become very duplication of job
i can i have a central error handler when my application starts
i get activated and so on
with Regards
sameer Mulgaonkar

-
Sep 5th, 2002, 12:30 AM
#4
-= B u g S l a y e r =-
Originally posted by sameer spitfire
So for every procedure in the form i have the write the code
is that so?
...
yes
-
Sep 5th, 2002, 01:28 AM
#5
Fanatic Member
This drives me nuts!!! Grrrrr... On Error events should have been classed to procedures, modules, public, etc. ages ago, just like variables. I usually end up making something to go through the code and write text for error handling for every procedure. What a pain!
-
Sep 5th, 2002, 01:38 AM
#6
PowerPoster
Originally posted by peet
yes
Does VB let you line jump to a label outside the current scope?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Sep 5th, 2002, 01:40 AM
#7
PowerPoster
Nope.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Sep 5th, 2002, 02:40 AM
#8
Addicted Member
i modded orion belt so that it also adds the error handler lines to each modual
On Error wake up and try again ;-)
___________________________
ICQ # 65392645
email - [email protected]
Visual Studio 6 ent with SP5 Running on XP with an AMD 1.2 ThunderBird with 512 MB RAM And a 120GB primary HDD (very sweet)
-
Sep 5th, 2002, 03:43 AM
#9
Well ...
You can have a public procedure in a standard module which accepts an error object (or its number and description etc.) and performs whatever actions you want to be taken on an error. Then you can simply call this procedure from each procedure's error handler. This way, although technically you have to write error handlers for every procedure, practically all your errors will be being handled at a central place. Also in this case since the error handlers in each procedure will be almost identical, you can use some tools such as MZTools (www.mztools.com) to insert a "procedure header" into your application which contains the error handler.
.
-
Sep 5th, 2002, 04:01 AM
#10
I use a module for error handling (that way I can have lots of functionality - eg: save errors to log files/email to me, nice messages for common errors..), but it needs to be called from each sub.
Here is the code that I copy & paste to use it:
VB Code:
On Error GoTo ErrorHandler:
Screen.MousePointer = vbHourglass
'** (module/function here) **
Err.Clear '(ignore errors under any previous Resume Next)
ErrorHandler: '** STANDARD ERROR HANDLING CODE: **
If Err > 0 Then
If Std_Error_Handler(Me.Name & " - **module/function name**", True, App.title, SQL) = "ignore" Then Resume Next
If ResumeNow Then Resume
End If
On Error Resume Next '** EXIT SUB/FUNCTION CODE (eg: re-enable form etc.) **
Screen.MousePointer = vbDefault
as you can see, "Std_Error_Handler" is the function that does it all, and returns "ignore" for a resume next, or sets the global "ResumeNow" to true for a resume (yes, I know now a Select Case would be better, but legacy code I'm afraid!).
-
Sep 5th, 2002, 04:54 AM
#11
Frenzied Member
Originally posted by rjlohan
Does VB let you line jump to a label outside the current scope?
If you have an error handler in the upper scope ( sub or whatever where other function or whatever calls are done)
and not in the ones you call from it , and an error occurs the error trap in the upper scope will trap it.
If you don't want to rewrite an error handler each time again , you could consider making your own add-in, make one which creates your own property's (get-let) functions , subs.
Then when you add a new function or sub or property do it with the add-in, this could make it a lot easier.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Sep 5th, 2002, 06:57 AM
#12
Well ...
Expanding on the above concept you could only have error handlers in the event procedures of your controls, and maybe in the Sub Main if you have one. This should probably make matters easier. The idea is to only have error handling in the topmost of all procedures. Barring the Sub Main and the control event procedures, all other procedures are actually on the second or later level of execution, i.e. they are called by either the Sub Main or the control event procedures. However the Sub Main and the control event procedures do not have any "callers", so to speak. Also an error that occurs in a procedure can be trapped by that procedure or by its calling procedure. Extending this idea further, if none of the procedures handle an error, it can be trapped in the topmost of procedures, which is the Sub Main or control event procedures.
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|