Try Catch Error Handling

  • Thread starter Thread starter CarpetMnuncher!
  • Start date Start date
C

CarpetMnuncher!

=================================================================
How do I use Try Catch error handling when a timer is involved?

If I preform the preciduer below and I get an error I revive
50,000,000,000,000,000, messageboxes..
example 1;
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Try
If Label13.Text = ("some text") = False Then
Button3.BackColor = System.Drawing.Color.FromArgb(CType(224,
Byte), CType(224, Byte), CType(224, Byte))
Button3.Text = ("some more text")
Timer5.Enabled = True '<<<<<<<<<<<< say this timer is error
free!
Timer6.Enabled = True '<<<<<<<<<<<< say this timer ha an error
and it kicks an exception error!
End If
Panel1.Visible = False
Catch ex As Exception
Dim proc As System.Diagnostics.Process
Dim pList() As Process
pList = Process.GetProcessesByName("some app")
For Each proc In pList
Dim resp As MsgBoxResult
resp = MsgBox("Error 0020 some error, Do you wish to Exit "
& proc.ProcessName & "?", _
MsgBoxStyle.YesNo, "app error")
If resp = MsgBoxResult.Yes Then
proc.Kill()
If resp = MsgBoxResult.No Then
Application.DoEvents()
End If
End If
Next
Exit Try
Finally
End Try
End Sub

If an exception error happens with the above code I get
50,0000,0000000000000,00000,000,0,0,00,,0,0,0,0,0,0,0,+1 messageboxes!
This next example works fine but it seames to me that it's overkill to have
too write my code twice, is ther another way to acoumplish the samething if
someone clickes NO???
Example 2;
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Try
If Label13.Text = ("some text") = False Then
Button3.BackColor = System.Drawing.Color.FromArgb(CType(224,
Byte), CType(224, Byte), CType(224, Byte))
Button3.Text = ("some more text")
Timer5.Enabled = True '<<<<<<<<<<<< say this timer is error
free!
Timer6.Enabled = True '<<<<<<<<<<<< say this timer ha an error
and it kicks an exception error!
End If
Panel1.Visible = False
Catch ex As Exception
Timer5.Enabled = False
Timer6.Enabled = False
Dim proc As System.Diagnostics.Process
Dim pList() As Process
pList = Process.GetProcessesByName("some app")
For Each proc In pList
Dim resp As MsgBoxResult
resp = MsgBox("Error 0020 some error, Do you wish to Exit "
& proc.ProcessName & "?", _
MsgBoxStyle.YesNo, "app error")
If resp = MsgBoxResult.Yes Then
proc.Kill()
If resp = MsgBoxResult.No Then
Application.DoEvents()
If Label13.Text = ("some text") = False Then
Button3.BackColor = System.Drawing.Color.FromArgb(CType(224,
Byte), CType(224, Byte), CType(224, Byte))
Button3.Text = ("some more text")
Timer5.Enabled = True '<<<<<<<<<<<< say this timer is error
free!
Timer6.Enabled = True '<<<<<<<<<<<< say this timer ha an error
and it kicks an exception error!
End If
Panel1.Visible = False
End If
End If
Next
Exit Try
Finally
End Try
End Sub
============================================================================
=
 
CarpetMnuncher! said:
Timer6.Enabled = True '<<<<<<<<<<<< say this timer ha an
error
and it kicks an exception error!


Where does the exception occur? In the event handler of the Timer? Is it a
System.Windows.Forms.Timer or a System.Timers.Timer?
 
Hi CarpetMnucher,

If I look at your code I get the idea that you don't use use the try, catch
end try to prevent unpredictable errors. But to catch program errors.

I cannot see how a timer process can make an error in an other way that that
there is an error in the code (or the computer is damaged and than will the
try and error block also not work).

Just a thought

Cor
 
Hello,
Here are your reply's

ARMIN
#1,,,,Where does the exception occur? In the event handler of the Timer? Is
it a
System.Windows.Forms.Timer or a System.Timers.Timer?
Answer = If an error occurs in the event handler of the timer.
My application uses both System.Windows.Forms.Timer-s, and
System.Timers.Timer-s.

COR
#2,,,,I cannot see how a timer process can make an error in an other way
that that
there is an error in the code (or the computer is damaged and than will the
try and error block also not work).
Answer= I agree, I think I'm attempting to how would you say "over-code my
code" here.

Form ME,
Now I'm Pissed I used try catch wrong = that sucks, I did the same thing to
about 40,000 thousand pulse events which = about 200,0000 hundred thousand
lines of code which = 381 windows forms, not incliding all the modules and
ouher stuff, I think I will grab a new pack of smokes and make a hole pot
of coffee for this task looks like another sleepless night for me man = Ha,
ha, ha, cry.
 
CarpetMnuncher! said:
Hello,
Here are your reply's

ARMIN
#1,,,,Where does the exception occur? In the event handler of the
Timer? Is it a
System.Windows.Forms.Timer or a System.Timers.Timer?
Answer = If an error occurs in the event handler of the timer.

Then you must put Try-Catch in the event handler.
My application uses both System.Windows.Forms.Timer-s, and
System.Timers.Timer-s.

And those mentioned (timer5, timer6) are?

Form ME,
Now I'm Pissed I used try catch wrong = that sucks, I did the same
thing to about 40,000 thousand pulse events which = about 200,0000
hundred thousand lines of code which = 381 windows forms, not
incliding all the modules and ouher stuff, I think I will grab a new
pack of smokes and make a hole pot of coffee for this task looks like
another sleepless night for me man = Ha, ha, ha, cry.

Do you see strange colors? ;-)) I understand you very well (or good?)....
 
I figured it out, I staled up all night "cut & Paste"-ing!
A pot of coffee, 1 pack of smokes, and a trip to the 24 hr store for a new
set of wireless mouse batteries, later I got it done and it works great.
Now I do see colors red, blue, and green dots, < I guess thats whay thay
call it .NET :))

I jest wanted to say thanks for your help !
____________________________________
 
CarpetMnuncher! said:
I figured it out, I staled up all night "cut & Paste"-ing!
A pot of coffee, 1 pack of smokes, and a trip to the 24 hr store for
a new set of wireless mouse batteries, later I got it done and it
works great. Now I do see colors red, blue, and green dots, < I guess
thats whay thay call it .NET :))
:-)))))

I jest wanted to say thanks for your help !

Problem solved? Glad to hear.. um.. read.
 
Back
Top