title: How can I throw an exception in an ASP.NET Core WebAPI controller that returns an object?
body: <p>In Framework WebAPI 2, I have a controller that looks like this:</p>
  
  <pre><code>[Route("create-license/{licenseKey}")]
  public async Task&lt;LicenseDetails&gt; CreateLicenseAsync(string licenseKey, CreateLicenseRequest license)
  {
      try
      {
          // ... controller-y stuff
          return await _service.DoSomethingAsync(license).ConfigureAwait(false);
      }
      catch (Exception e)
      {
          _logger.Error(e);
          const string msg = "Unable to PUT license creation request";
          throw new HttpResponseException(HttpStatusCode.InternalServerError, msg);
      }
  }
  </code></pre>
  
  <p>Sure enough, I get back a 500 error with the message.</p>
  
  <p>How can I do something similar in ASP.NET Core Web API? </p>
  
  <p><code>HttpRequestException</code> doesn't seem to exist. I would prefer to continue returning the object instead of <code>HttpRequestMessage</code>.</p>