By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Try Catch Error Handling

P: n/a
================================================== ===============
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
================================================== ==========================
=

Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"CarpetMnuncher!" <Ba*@mail.com> schrieb
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?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
Cor
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

Nov 20 '05 #3

P: n/a
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.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...
"CarpetMnuncher!" <Ba*@mail.com> schrieb
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?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

P: n/a
"CarpetMnuncher!" <Ba*@mail.com> schrieb
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?)....
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a
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 !
____________________________________
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
"CarpetMnuncher!" <Ba*@mail.com> schrieb
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?)....
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6

P: n/a
"CarpetMnuncher!" <Ba*@mail.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7

P: n/a
Cor
Hi "CarpetMnuncher!"

I jest wanted to say thanks for your help !
____________________________________

:-((

Only Armin?

Cor
Nov 20 '05 #8

P: n/a
And this is why I love software development.

=)

"Armin Zingler" <az*******@freenet.de> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
"CarpetMnuncher!" <Ba*@mail.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.