CKTIS / C#
System.FormatException: referência prática
System.FormatException: referência prática: FormatException indica texto que não respeita a sintaxe esperada por um analisador ou formatador.
Versão: .NET API; verified on .NET 10.0.14
Sintaxe
System.FormatException /* select a documented member or constructor */FormatException indica texto que não respeita a sintaxe esperada por um analisador ou formatador.
Usa TryParse para entrada previsível do utilizador e reserva a exceção para violações do contrato de programação.
A cultura e NumberStyles fazem parte do formato, pelo que o mesmo texto pode ter significados diferentes.
Texto vazio ou em branco normalmente falha; um número fora do intervalo lança OverflowException em vez disso.
O programa completo usa realmente System.FormatException; o stdout exato esperado é FormatException.
Exemplos
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); }
Resultado
FormatException
O programa completo usa realmente `System.FormatException`; o stdout exato esperado é `FormatException`.