Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:50:32+00:00 2026-06-09T15:50:32+00:00

Using Asp.net WebApi (RC), how can I catch errors that are not caught by

  • 0

Using Asp.net WebApi (RC), how can I catch errors that are not caught by Exception Filters or Application_Error() in global.asax?

With both of these in place it seems that there is a class of exceptions still not covered. For example: ApiControllerActionSelector_AmbiguousMatch error (Multiple actions were found that match the request: {0}).

I’m not specifically concerned about the above error, this error just pointed out that there is a class of errors that aren’t being caught by either my Exception Filter or Application_Error method.

So how can I cover all my bases?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:50:33+00:00Added an answer on June 9, 2026 at 3:50 pm

    You’re right, there are several classes of exception not trapped by either Application_Error or ExceptionFilter. The Web API request pipeline is processed separately from the ASP.NET MVC pipeline (at least through MVC 4) so the MVC Application_Error doesn’t kick-in. Also, if your application throws HttpResponseException type exceptions, they will not be caught by an ExceptionFilter by design (see the ExceptionFilter paragraph). To access all exceptions thrown by your code, you’ll need to create a DelegatingHandler along the lines of this code:

    public class ResponseExceptionTrapper : DelegatingHandler
    {
        protected override Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            return base
                .SendAsync(request, cancellationToken)
                .ContinueWith(response =>
                     {
                         var result = response.Result;
                         if (!result.IsSuccessStatusCode)
                         {
                              var exceptionResult = string.Format(
                                   "Response exception: Path({0}) Status({1}) ",
                                   request.RequestUri,
                                   result.StatusCode);
    
                              if (result.Content != null)
                              {
                                   var exceptionReadTask =
                                          result.Content.ReadAsStringAsync();
    
                                   exceptionReadTask.Wait();
                                   exceptionResult += "Message:\n\r" +
                                                     exceptionReadTask.Result;
                               }
    
                               // Do something appropriate with exceptionResult
                          }
    
                          return result;
                     }, cancellationToken);
        }
    }
    

    You can wire up the handler with this line in your global config logic:

    GlobalConfiguration.Configuration.MessageHandlers.Add(
         new ResponseExceptionTrapper());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the new ASP.NET Web API beta. I can not seem to get the
I'm creating REST service using ASP.NET Web API. How can I return 401 status
Prior to the asp.net 4 RC update, I had been using the WebApi for
ASP.NET MVC4 Beta introduced an easy way to create OData endpoints using WebAPI. So
How can I make a method with two parameters using ASP.NET Web Api? So
I'm using the wcf webapi to get data from my asp.net application, and trying
Using the ASP.NET WebApi 4 RC, is it possible to have an ApiController's return
I'm using ASP.NET WebAPI RC, and hosting an API controller with nothing fancy about
I'm trying to query my EF Model (using ASP.NET MVC WebApi) but only the
I'm creating an application that has a ASP.NET Web API interface using the Self

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.