M
Mr Flibble
Hi all, happy Friday! (certainly Friday is a day worth celebrating).
I have a question on try/catch design (an exciting Friday topic for sure):
I can either put a try/catch block in every function and have each one
of those handle and log the error in some way (I'm thinking of using
log4net), or I can still have a try/catch block in every function but in
each I simply re-throw the error attaching the object to the inside
(creating an error stack) and then just have some "top level" block
catch and log the error (by looking through the stack to determine the
cause of the exception).
If I choose to do it the latter way, I'll have to make sure my error
objects contain all the details (variables) that I may need to inspect,
whereas if I do it the former way, I would obviously have all this
information available to me locally where the exception actually occured.
I'm at a loss over which is better/best practice.
Can anyone please advise which is the better approach?
Many thanks,
Mr Flibble
I have a question on try/catch design (an exciting Friday topic for sure):
I can either put a try/catch block in every function and have each one
of those handle and log the error in some way (I'm thinking of using
log4net), or I can still have a try/catch block in every function but in
each I simply re-throw the error attaching the object to the inside
(creating an error stack) and then just have some "top level" block
catch and log the error (by looking through the stack to determine the
cause of the exception).
If I choose to do it the latter way, I'll have to make sure my error
objects contain all the details (variables) that I may need to inspect,
whereas if I do it the former way, I would obviously have all this
information available to me locally where the exception actually occured.
I'm at a loss over which is better/best practice.
Can anyone please advise which is the better approach?
Many thanks,
Mr Flibble