Web
Analytics
Exception handing in web api 2 using example - Tutorial

For Consultation : +91 9887575540

Stay Connected :

How many ways of Exception Handling

1.HttpResponseException

2.HttpError

3.Exception Filters

  1. HttpResponseException Class:

This exception returns any HTTP status code that you specify in the exception constructor.





2. Http Error:

▸CreateErrorResponse method of Request object helps us to return meaningful error code and message to the client.

▸ CreateErrorResponse creates an instance of HttpError object and returns it as HttpResponseMessage object.

CreateErrorResponse is an extension method defined in the System.Net.Http.HttpRequestMessageExtensions class.

 

HttpResponseException  Example Source Code

 

 

 HttpError Example Source Code

 





Select your currency