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 8591195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:28:16+00:00 2026-06-11T23:28:16+00:00

Does anyone know why the behaviour of throwing exceptions within a PUT action method

  • 0

Does anyone know why the behaviour of throwing exceptions within a PUT action method in a controller in ASP.NET WebAPI would be different from any other actions and verb types?

Essentially I have the code below (I normally have an exception filter globally registered but I’ve disabled that to ensure it isn’t the cause).

public class JourneysController : ApiController
{
    private IJourneyRepository repository = null;

    public JourneysController(IJourneyRepository repository)
    {
        this.repository = repository;
    }

    public async Task<Journey> GetById(string id)
    {
        throw new BusinessException("test1");

        var item = await repository.Get(id);
        if (item == null) throw new HttpResponseException(HttpStatusCode.NotFound);
        return item;
    }

    public async Task<HttpResponseMessage> Post(HttpRequestMessage request, [FromBody]Journey value)
    {
        throw new BusinessException("test2");

        value = await repository.Add(value);

        var response = request.CreateResponse<Journey>(HttpStatusCode.Created, value);

        string uri = Url.Link("DefaultApi", new { id = value.Id });
        response.Headers.Location = new Uri(uri);
        return response;
    }

    public async void Put(string id, [FromBody]Journey value)
    {
        throw new BusinessException("test3");

        value.Id = id;
        if (!await repository.Update(value)) throw new HttpResponseException(HttpStatusCode.NotFound);
    }

    public HttpResponseMessage Delete(string id)
    {
        throw new BusinessException("test4");

        repository.Remove(id);
        return new HttpResponseMessage(HttpStatusCode.NoContent);
    }
}

When I execute (using Chrome Advanced REST client) the GET, POST and DELETE verbs I get a payload like the following (no easy way to copy/paste out of the client):

500 Internal Server Error 

Date: Tue, 25 Sep 2012 15:37:56 GMT 
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 813 
Pragma: no-cache 

{
    "Message": "An error has occurred.",
    "ExceptionMessage": "test4",
    "ExceptionType": "KieranBenton.LeaveNow.Services.Model.BusinessException",
    "StackTrace": " <snip>"
}

However the PUT action returns me a yellow screen of death payload like:

<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

        <h2> <i>test3</i> </h2></span>

        <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

        <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

        <b> Exception Details:    </b>KieranBenton.LeaveNow.Services.Model.BusinessException: test3

Has anyone got any idea why this might be happening or if I’ve actually stumbled across a bug?

Thanks.

  • 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-11T23:28:17+00:00Added an answer on June 11, 2026 at 11:28 pm

    One guideline for async is to avoid async void.

    The async equivalent of a synchronous method returning void is an async method returning Task. async void only exists so that event handlers may be async.

    As you noticed, the exception handling is different. Any exceptions raised from an async void are sent directly to the SynchronizationContext that was current when the method started. This is natural for event handlers, but is confusing in other scenarios.

    ASP.NET establishes a SynchronizationContext that represents the current HTTP request, so any exceptions from an async void method are not passed up to the WebAPI code that’s running the controller; they get passed around the WebAPI framework straight to the ASP.NET request context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a framework that would allow me to easily host and
My XCode connects to static.ak.facebook.com.edgesuite.net and downloads something off there. Does anyone know what
Does anyone know if it is possible to access via code either from within
Does anyone know how IIS/.NET web services handle call-concurrency? I can think of two
Does anyone know if there is a way to generate different code in the
Does anyone know of a free tool, similar to what is built into Visual
Does anyone know why UsernameExists wont return True. I must have my syntax messed
Does anyone know of a mechanism in Sybase ASA 9 / Sybase SQL Anywhere
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know of a way to contain a nonbreaking space in an html

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.