In my services all exposed methods have:
try
{
// the method core is written here
}
catch(Exception ex)
{
Log.Append(ex);
}
It’s boring and ugly to repeat it over and over again. Is there any way to avoid that? Is there a better way to keep the service working even if exceptions occur and keep sending the exception details to the Log class?
You could set up a generic error handling method for all uncaught exceptions like so:
Depending on what went wrong, you may not be able to recover from the error… but this should hopefully give you some idea of what what went wrong. If it gets to the point where your application code hasn’t handled the exception gracefully, this method could attempt to reinitialize the service to a known working state.