Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.FormatException: referencia práctica

System.FormatException: referencia práctica: FormatException indica texto que no cumple la sintaxis esperada por un analizador o formateador.

Versión: .NET API; verified on .NET 10.0.14

Sintaxis

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

FormatException indica texto que no cumple la sintaxis esperada por un analizador o formateador.

Usa TryParse para entrada de usuario previsible y reserva la excepción para contratos de programación incumplidos.

La cultura y NumberStyles forman parte del formato, por lo que el mismo texto puede significar algo distinto.

El texto vacío o en blanco suele fallar; un número fuera de rango lanza OverflowException en su lugar.

El programa completo usa realmente System.FormatException; su stdout esperado exacto es FormatException.

Ejemplos

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

El programa completo usa realmente `System.FormatException`; su stdout esperado exacto es `FormatException`.

Fuentes