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

Only One Try...End Try for all all the procedures...

P: n/a
Scenario:

I have 10 buttons on the Windows form. All the 10 buttons have lengthy code.
I don't want to put Try..End Try Exception Handler in all the 10 procedure
handling 10 clicks events of 10 buttons. Is it possible that I only use only
one exception handler for my complete FORM or PROJECT or
APPLICATION....................... I know this sounds like a stupid
idea.....but this is not the issue....the issue is whether it can be
done................
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Not stupid at all - in fact very useful.

The basic strategy is:

1) Start your application with a sub main
2) In the sub main create a new instance of your "main" form (lets call it
yourform)
3) wrap application.run(yourform) in a try catch block.

Any errors that bubble to the top will be handled. However, it will also
cause your app to exit.

If you want a global error handler that doesn't necessarily exit, check out
this example on gotdotnet. I think this technique is great. I've used it to
help users send emails to me with stack traces of unanticpated behavior,
while allowing them to resume execution until they can save and restart or
what not.

http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:#t**************@TK2MSFTNGP09.phx.gbl...
Scenario:

I have 10 buttons on the Windows form. All the 10 buttons have lengthy code. I don't want to put Try..End Try Exception Handler in all the 10 procedure
handling 10 clicks events of 10 buttons. Is it possible that I only use only one exception handler for my complete FORM or PROJECT or
APPLICATION....................... I know this sounds like a stupid
idea.....but this is not the issue....the issue is whether it can be
done................

Nov 20 '05 #2

P: n/a

"Justin Weinberg" <jweinberg@_spamkill_mrgsoft.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
Not stupid at all - in fact very useful.

I'm not saying its not stupid. Because I do it on my code so my code
doesn't exit. I think the global event handler (as used at gotdotnet) is a
much better approach...

However, I am a big proponent of using many Try Catches, that way you have
less GIGO... At least I do... My applications may be a bit bulkier than
others, but if something goes wrong, I know exactly where and why.

But I'm anal like that...

and weird... =)
The basic strategy is:

1) Start your application with a sub main
2) In the sub main create a new instance of your "main" form (lets call it
yourform)
3) wrap application.run(yourform) in a try catch block.

Any errors that bubble to the top will be handled. However, it will also
cause your app to exit.

If you want a global error handler that doesn't necessarily exit, check out this example on gotdotnet. I think this technique is great. I've used it to help users send emails to me with stack traces of unanticpated behavior,
while allowing them to resume execution until they can save and restart or
what not.

http://samples.gotdotnet.com/quickst...FormsAppErrorH andler.aspx

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:#t**************@TK2MSFTNGP09.phx.gbl...
Scenario:

I have 10 buttons on the Windows form. All the 10 buttons have lengthy

code.
I don't want to put Try..End Try Exception Handler in all the 10 procedure handling 10 clicks events of 10 buttons. Is it possible that I only use

only
one exception handler for my complete FORM or PROJECT or
APPLICATION....................... I know this sounds like a stupid
idea.....but this is not the issue....the issue is whether it can be
done................


Nov 20 '05 #3

P: n/a
LOL
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.