---
title: "Explain the differences between ArgumentException and ArgumentNullException."  
description: "Explain the differences between ArgumentException and ArgumentNullException."  
author: "Steilla Mitchel"  
published: 2023-08-30  
updated: 2023-09-02  
canonical: https://www.mindstick.com/forum/159753/explain-the-differences-between-argumentexception-and-argumentnullexception  
category: ".net core"  
tags: ["exception handling", "exception", "asp.net core", ".net core"]  
reading_time: 2 minutes  

---

# Explain the differences between ArgumentException and ArgumentNullException.

[Explain the differences](https://www.mindstick.com/forum/158322/explain-the-differences-between-prototypal-and-classical-inheritance-in-javascript) between **[ArgumentException](https://www.mindstick.com/forum/158623/what-is-an-argumentexception-and-when-might-it-be-thrown-in-an-asp-dot-net-mvc-project)** and **ArgumentNullException**.

## Replies

### Reply by Aryan Kumar

Sure. The main difference between ArgumentException and ArgumentNullException is that ArgumentException is thrown when an argument passed to a method is invalid, while ArgumentNullException is thrown when an argument passed to a method is null.

Here is a table summarizing the key [differences](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences) between ArgumentException and ArgumentNullException:

| Feature | ArgumentException | ArgumentNullException |
| --- | --- | --- |
| When is it thrown? | When an argument passed to a method is invalid. | When an argument passed to a method is null. |
| What is the message? | The message describes the invalid argument. | The message specifies the argument that is null. |
| Where is it inherited from? | ArgumentException inherits from Exception. | ArgumentNullException inherits from ArgumentException. |

Here are some examples of ArgumentException:

- Passing a string to a method that expects an integer.
- Passing a negative number to a method that expects a positive number.
- Passing a null string to a method that expects a non-null string.

Here are some examples of ArgumentNullException:

- Passing null to a method that expects an integer.
- Passing null to a method that expects a string.
- Passing null to a method that expects an array.

It is important to use the correct exception type when handling errors. If you use ArgumentException when you should have used ArgumentNullException, the error message will not be very helpful.

In general, you should use ArgumentNullException when an argument is passed to a method and it is null. You should use ArgumentException when an argument is passed to a method and it is invalid, but not null.


---

Original Source: https://www.mindstick.com/forum/159753/explain-the-differences-between-argumentexception-and-argumentnullexception

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
