CKTIS / C#
catch: référence pratique
catch: référence pratique: catch intercepte une exception de type compatible après l’échec d’un try.
Version : C# language and .NET 10 reference runtime
Syntaxe
catch /* grammar-specific form */catch intercepte une exception de type compatible après l’échec d’un try.
Interceptez seulement là où récupération, contexte ou traduction sont possibles.
Un catch trop large masque les défauts ; throw conserve la pile, throw ex la réinitialise.
Un filtre when s’exécute avant catch et ne devrait pas lui-même lever.
Le programme complet utilise réellement catch ; sa sortie stdout exacte attendue est caught.
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 { throw new InvalidOperationException(); } catch (InvalidOperationException) { Console.WriteLine("caught"); }
Résultat
caught
Le programme complet utilise réellement `catch` ; sa sortie stdout exacte attendue est `caught`.