469,644 Members | 1,696 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

Try Catch Error Handling

================================================== ===============
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
8 1508
"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
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
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
"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
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
"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
Cor
Hi "CarpetMnuncher!"

I jest wanted to say thanks for your help !
____________________________________

:-((

Only Armin?

Cor
Nov 20 '05 #8
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.

Similar topics

4 posts views Thread by Evgeny Gopengauz | last post: by
7 posts views Thread by Dan Bass | last post: by
37 posts views Thread by clintonG | last post: by
23 posts views Thread by VB Programmer | last post: by
9 posts views Thread by Michael MacDonald | last post: by
4 posts views Thread by DavideR | last post: by
32 posts views Thread by cj | last post: by
23 posts views Thread by pigeonrandle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.