I have a Web API 2 controller action which returns a list of users
public List<User> GetAll()
{
try
{
return _businessLogic.GetAll();
}
catch (Exception ex)
{
ExceptionHelper.HandleException(ex, _logger, ControllerContext);
}
}
class ExceptionHelper {
public static void HandleException(Exception ex, ILogger _logger, HttpControllerContext controllerContext) {
_logger.LogError(ex);
// If possible handle the exception here
// Code for handling
// Throw it again
throw new HttpResponseException(
controllerContext.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessagError)
);
}
}
C# compiler is complaining that not all code paths in GetAll()
return a value.
The thing is, I don't want to return anything when an exception occurs, because the HandleException
will log the error and throw an exception again. How do I explicitly say that I don't want to return anything.