views:

169

answers:

2

I have read it here : CodeProject and some other places that there should be a single catch block per thread. I don't quite understand this in context of winforms. Is it true also in case of winforms? I understand that worker threads should have a single catch block. But, I have multiple catch blocks on the UI(main) thread which always end up calling my private HandleError method passing the exception. This method then takes care about how to display the errors to an user. So, say I might have a try/catch block in button1_click handler and another try/catch block in another button2_click handler. Is this a good practice? Can someone tell me if I should do something differently. Thanks.

+1  A: 

I don't know of any real "rule" for using try/catch blocks. Though I'm no fan of one big try block. Use them wisely on points / lines of code where you expect possible exceptions.

Henrik P. Hessel
+1  A: 

I think you should read that rule as "there should at least be a single catch block per thread". Every thread, and certainly the main thread, should use catch blocks wherever appropriate.

Henk Holterman