Sunday, October 9, 2016

HttpResponseException was Unhandled by user code.

In order to reach broad range of clients including browsers or mobile devices ,industry is moving towards using HTTP based restful services.Asp.Net Web API is an ideal platform for building restful services using .Net Framework. 
Exception handling is one of the most important thing that we use while creating any application .If we try to throw exception from an Action method within Web API, may be you will face the following exception "HttpResponseException was Unhandled by user code."
This is actually not an error, actually you are throwing an exception that will go outside the user code and needs to be handled by the framework to generate HTTP response that need to be send to the client. So to solve this issue we need to add an exception in Exceptions within debug menu of visual studio. 
In Visual Studio 2015 select Debug => Windows => Exception Settings 


In the Exception Settings ,Go to Common Language Runtime.


Right Click On Common Language Run time Exceptions and Click Add Exception. Enter the Exception Type as “System.Web.Http.HttpResponseException”. Right Click on the newly added exception and Click Continue When Unhanded in User Code.