Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / C#

System.FormatException: praktická reference

System.FormatException: praktická reference: FormatException označuje text, který neodpovídá syntaxi očekávané parserem nebo formátovačem.

Verze: .NET API; verified on .NET 10.0.14

Syntaxe

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

FormatException označuje text, který neodpovídá syntaxi očekávané parserem nebo formátovačem.

Pro očekávaný uživatelský vstup použijte TryParse a výjimku ponechte pro porušení programového kontraktu.

Kultura a NumberStyles jsou součástí formátu, takže stejný text může mít jiný význam.

Prázdný text či mezery obvykle selžou; číslo mimo rozsah vyvolá místo toho OverflowException.

Úplný program skutečně používá System.FormatException; přesně očekávaný stdout je FormatException.

Příklady

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 { int.Parse("x", CultureInfo.InvariantCulture); } catch (FormatException error) { Console.WriteLine(error.GetType().Name); }

Výsledek

FormatException

Úplný program skutečně používá `System.FormatException`; přesně očekávaný stdout je `FormatException`.

Zdroje