microbolt
asked on
Error Reporting Function Best Practices
Hello Experts
Currently I at the start and end of each function I have a try catch block to catch any errors which then calls a function to report any unhandled errors to our webservice. Here is how we currently do it:
private void SomeFunction()
{
#region Try (ErrorReporting)
#if !DEBUG
try
{
#endif
#endregion
// Code for function here
#region Catch (ErrorReporting)
#if !DEBUG
}
catch (Exception Ex)
{
DefaultErrorHandling(Ex);
}
#endif
#endregion
}
Can anyone think of a better way to handle this? or is the an effecient way of doing this? We have the #ifdef !DEBUG so that it doesn't compile the error catching to make debuging easier. And the regions are there just so we can collapse the section because its real ugly code to look at in every routine :)
My question is what is your prefered method for catching errors and is there a more effecient method for us to use. And secondly, is there a better method for catching than putting a try...catch in every function?
Thanks!
Currently I at the start and end of each function I have a try catch block to catch any errors which then calls a function to report any unhandled errors to our webservice. Here is how we currently do it:
private void SomeFunction()
{
#region Try (ErrorReporting)
#if !DEBUG
try
{
#endif
#endregion
// Code for function here
#region Catch (ErrorReporting)
#if !DEBUG
}
catch (Exception Ex)
{
DefaultErrorHandling(Ex);
}
#endif
#endregion
}
Can anyone think of a better way to handle this? or is the an effecient way of doing this? We have the #ifdef !DEBUG so that it doesn't compile the error catching to make debuging easier. And the regions are there just so we can collapse the section because its real ugly code to look at in every routine :)
My question is what is your prefered method for catching errors and is there a more effecient method for us to use. And secondly, is there a better method for catching than putting a try...catch in every function?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good Stuff. Exactly what I was looking for.
"One final point, an exception worth catching in a debug build is also worth catching in a release build."
is very important. Leaks are more dangerous in Release builds where apps run a long time than they are in a 5 minute debugger session. And graceful failure handling is more important to you when your customers are running that release build.