Click here to Skip to main content
15,920,628 members
Home / Discussions / C#
   

C#

 
GeneralRe: Is try - catch block advisable? Pin
Forbiddenx23-Aug-13 6:37
Forbiddenx23-Aug-13 6:37 
GeneralRe: Is try - catch block advisable? Pin
Eddy Vluggen24-Aug-13 2:49
professionalEddy Vluggen24-Aug-13 2:49 
GeneralRe: Is try - catch block advisable? Pin
PIEBALDconsult23-Aug-13 18:55
mvePIEBALDconsult23-Aug-13 18:55 
GeneralRe: Is try - catch block advisable? Pin
jschell23-Aug-13 13:16
jschell23-Aug-13 13:16 
GeneralRe: Is try - catch block advisable? Pin
PIEBALDconsult23-Aug-13 18:55
mvePIEBALDconsult23-Aug-13 18:55 
AnswerRe: Is try - catch block advisable? Pin
Ennis Ray Lynch, Jr.23-Aug-13 3:13
Ennis Ray Lynch, Jr.23-Aug-13 3:13 
GeneralRe: Is try - catch block advisable? Pin
PIEBALDconsult23-Aug-13 18:56
mvePIEBALDconsult23-Aug-13 18:56 
AnswerRe: Is try - catch block advisable? Pin
jschell23-Aug-13 13:26
jschell23-Aug-13 13:26 
I catch everything on layer boundaries. What happens there depends on the layer and where I catch it.

I catch everything on adapter boundaries, although that is just a specialization of a layer boundary. However I also tend to catch everything at the adapter top level as well.

When I catch everything then handling involves the following
1. log it, and take appropriate action which might include throwing a different exception WITHOUT including the original exception.
2. Don't log it and take appropriate action which might include throwing a different exception INCLUDING the original exception in the new exception.

I do NOT use catch alls which do nothing but log and then rethrow. That is pointless and a waste of time since the caller should be catching and will then end up logging as well.

There are of course extreme conditions where the above can be problematic. For example out of memory errors. Those can cause the log to fail as well. However without some logging figuring out an out of memory occurred is impossible. There are things like stack over flow in C# which CANNOT be caught so one is kind of out luck there.

This however does NOT mean that one can ignore the code that one is working with. If I am working on a communications layer then I expect communication exceptions. And I expect to take specific actions with regards to those.

I suppose what it really comes down to is that I use catch all because I am almost certain that some unexpected exception will occur at some point and I need to still behave in some reasonable manner. At other times I am not certain and thus it is inappropriate to take such action. Which is why boundary layers are often the only place this occurs.
AnswerRe: Is try - catch block advisable? Pin
PIEBALDconsult23-Aug-13 16:20
mvePIEBALDconsult23-Aug-13 16:20 
AnswerRe: Is try - catch block advisable? Pin
Abhinav S23-Aug-13 16:44
Abhinav S23-Aug-13 16:44 
GeneralRe: Is try - catch block advisable? Pin
Eddy Vluggen24-Aug-13 0:55
professionalEddy Vluggen24-Aug-13 0:55 
GeneralRe: Is try - catch block advisable? Pin
OriginalGriff24-Aug-13 1:37
mveOriginalGriff24-Aug-13 1:37 
GeneralRe: Is try - catch block advisable? Pin
Eddy Vluggen24-Aug-13 2:34
professionalEddy Vluggen24-Aug-13 2:34 
GeneralRe: Is try - catch block advisable? Pin
OriginalGriff24-Aug-13 2:40
mveOriginalGriff24-Aug-13 2:40 
GeneralRe: Is try - catch block advisable? Pin
Eddy Vluggen24-Aug-13 7:18
professionalEddy Vluggen24-Aug-13 7:18 
GeneralRe: Is try - catch block advisable? Pin
jschell26-Aug-13 8:43
jschell26-Aug-13 8:43 
GeneralRe: Is try - catch block advisable? Pin
OriginalGriff24-Aug-13 1:38
mveOriginalGriff24-Aug-13 1:38 
GeneralRe: Is try - catch block advisable? Pin
Abhinav S24-Aug-13 2:07
Abhinav S24-Aug-13 2:07 
GeneralRe: Is try - catch block advisable? Pin
Eddy Vluggen24-Aug-13 2:39
professionalEddy Vluggen24-Aug-13 2:39 
GeneralRe: Is try - catch block advisable? Pin
OriginalGriff24-Aug-13 2:43
mveOriginalGriff24-Aug-13 2:43 
GeneralRe: Is try - catch block advisable? Pin
Eddy Vluggen24-Aug-13 2:54
professionalEddy Vluggen24-Aug-13 2:54 
GeneralRe: Is try - catch block advisable? Pin
jschell26-Aug-13 8:53
jschell26-Aug-13 8:53 
AnswerRe: Is try - catch block advisable? Pin
Brian Holsen25-Aug-13 18:18
Brian Holsen25-Aug-13 18:18 
AnswerRe: Is try - catch block advisable? Pin
V.26-Aug-13 3:11
professionalV.26-Aug-13 3:11 
QuestionGet User Privileges in a machine for a specific user Pin
Rijz22-Aug-13 20:10
Rijz22-Aug-13 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.