Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.ArgumentException: odniesienie praktyczne

System.ArgumentException: odniesienie praktyczne: ArgumentException oznacza argument nie-null niezgodny z kontraktem i może zachować ParamName.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

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

ArgumentException oznacza argument nie-null niezgodny z kontraktem i może zachować ParamName.

Rzucaj na publicznej granicy po wykryciu nieprawidłowej wartości argumentu.

Nie steruj logiką tekstem Message, bo jest lokalizowany; preferuj konkretniejsze podtypy.

ParamName może być null; samo złapanie wyjątku nie naprawia błędnej wartości.

Kompletny program rzeczywiście używa System.ArgumentException; oczekiwany stdout to dokładnie value.

Przykłady

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); }

Wynik

value

Kompletny program rzeczywiście używa `System.ArgumentException`; oczekiwany stdout to dokładnie `value`.

Źródła