Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

ExceptionFilterAttribute - returned HttpResponseException is caught by visual studio

$
0
0

Hi

In order to get to the bottom of an error I was having in my controller, I created my own ExceptionFilterAttribute and registered it for the controller (as described here: http://weblogs.asp.net/fredriknormen/asp-net-web-api-exception-handling - I'm using the ExceptionHandlingAttribute class posted there).

Now, if something goes wrong in a controller method, I do get the OnException in my ExceptionFilterAttribute. And then, when I get to the code where the custom error is returned

throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent("An error occurred, please try again or contact the administrator."),
                ReasonPhrase = "Critical Exception"
            });

Visual studio catches this and informs me that there's an HttpResponseException that's not handled by user code. 

Of course there is.. this thing is supposed to go to the client. 

Shouldn't this not pop up as throwing the HttpResponseException at this point is how you're supposed to return something to the client?


Viewing all articles
Browse latest Browse all 4850


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>