Base de connaissancesCentre d’examen
FRFrançais
Choisir la langue13

CKTIS / C#

System.FormatException: référence pratique

System.FormatException: référence pratique: FormatException signale un texte qui ne respecte pas la syntaxe attendue par un analyseur ou formateur.

Version : .NET API; verified on .NET 10.0.14

Syntaxe

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

FormatException signale un texte qui ne respecte pas la syntaxe attendue par un analyseur ou formateur.

Utilisez TryParse pour une entrée utilisateur prévisible et réservez l’exception à une violation de contrat.

Culture et NumberStyles font partie du format ; un même texte peut donc avoir plusieurs significations.

Un texte vide ou blanc échoue généralement ; une valeur hors plage lève plutôt OverflowException.

Le programme complet utilise réellement System.FormatException ; sa sortie stdout exacte attendue est FormatException.

Exemples

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

Résultat

FormatException

Le programme complet utilise réellement `System.FormatException` ; sa sortie stdout exacte attendue est `FormatException`.

Sources