---
title: "What is a HttpRequestException, and how to handle it during external HTTP requests?"  
description: "What is a HttpRequestException, and how to handle it during external HTTP requests?"  
author: "Steilla Mitchel"  
published: 2023-08-30  
updated: 2023-08-31  
canonical: https://www.mindstick.com/forum/159761/what-is-a-httprequestexception-and-how-to-handle-it-during-external-http-requests  
category: ".net core"  
tags: ["exception handling", "http request", "exception", "asp.net core", ".net core"]  
reading_time: 2 minutes  

---

# What is a HttpRequestException, and how to handle it during external HTTP requests?

What is a **HttpRequestException**, and how to [handle](https://www.mindstick.com/articles/311004/suede-skillet-handle-cover) it during [external](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) [HTTP requests](https://www.mindstick.com/articles/1406/debugging-http-requests-and-http-response)?

## Replies

### Reply by Aryan Kumar

An HttpRequestException is a class in the System.Net.[Http](https://www.mindstick.com/blog/217/http-endpoints-in-sql-server-2005-2008) namespace that represents an error that occurred during an HTTP request. It can be thrown by the HttpClient class when an error occurs, such as a network error or a server error.

To handle an HttpRequestException during an external HTTP request, you can use a try/catch block. The following code shows an example of how to do this:

C#

```plaintext
try
{
    // Make the HTTP request.
}
catch (HttpRequestException ex)
{
    // Handle the error.
    Console.WriteLine(ex.Message);
}
```

In this code, the `try` block makes the HTTP request. If the request fails, the `catch` block will be executed and the error message will be displayed in the console.

Here are some additional things to keep in mind when handling HttpRequestExceptions:

- The `HttpRequestException` class has a property called `StatusCode` that contains the HTTP status code of the error. This property can be used to get more information about the error.
- The `HttpRequestException` class also has a property called `InnerException` that contains the inner exception. This property can be used to get the underlying exception that caused the `HttpRequestException`.
- The `HttpRequestException` class can be handled in the same way as any other exception.


---

Original Source: https://www.mindstick.com/forum/159761/what-is-a-httprequestexception-and-how-to-handle-it-during-external-http-requests

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
