![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Exception Handling and Events
Hi Friends!
I have been away for a while, now I'm planning to come back here and participate actively again. Anyways, coming to the question:- As per my understanding, we should not place try... catch statements in every function where we want to handle exceptions instead we should let the exceptions rise up in the function call hierarchy and handle all the exceptions at one place. That sounds fine. But I'm having problems using this technique in event driven programming. For example, I have a C# windows application and I open one main form from where I can open several pop-up forms. Now, I want to handle all the exceptions in the main form. Now suppose, In one pop-up form, I've a button and I attach one Click event handler to that. and In that event handler, an Exception is thrown, I cannot catch that exception in the main form as the event wasn't raised from the main form but the button class. Any suggestions how can I implement this?
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Re: Exception Handling and Events
I found something related to the above here . I'll look into it in detail later on.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Re: Exception Handling and Events
Attaching to Application.ThreadException - will only help you when an unexpected exception happens (and you'll show something like - app died , sorry
) - but there are cases when certain exception can be caught and recovered from. So, i think that exceptions shouldn't be caught only at top level, but that every form can catch some exceptions also.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#4 | |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,295
Rep Power: 5
![]() |
Re: Exception Handling and Events
Quote:
Of course, doing it this way means sprinkling the code with try/catch blocks, which can clutter up the code. Your best option is probably to design the code in such a way as to limit which exceptions can be thrown when, and then wrap this localized code in a try/catch block.
__________________
Java? Rant? Me? Noooo.... |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Priority Queues Events | kruptof | C# | 12 | Sep 6th, 2007 6:56 PM |