Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.ArgumentException: practical reference

System.ArgumentException: practical reference: ArgumentException denotes a non-null argument that violates the contract and can retain its ParamName.

Version: .NET API; verified on .NET 10.0.14

Syntax

System.ArgumentException /* select a documented member or constructor */

ArgumentException denotes a non-null argument that violates the contract and can retain its ParamName.

Throw it at a public boundary after detecting an invalid argument value.

Do not drive logic from Message text because it is localized; prefer a more specific subtype.

ParamName can be null; merely catching the exception does not repair the invalid value.

The complete program actually uses System.ArgumentException; its exact expected stdout is value.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

try { throw new ArgumentException("invalid", "value"); } catch (ArgumentException error) { Console.WriteLine(error.ParamName); }

Result

value

The complete program actually uses `System.ArgumentException`; its exact expected stdout is `value`.

Sources