CKTIS / C#
System.OverflowException: référence pratique
System.OverflowException: référence pratique: OverflowException signale un résultat numérique hors de la plage du type cible dans un contexte checked ou une conversion.
Version : .NET API; verified against .NET 10 reference surface
Syntaxe
System.OverflowException /* select a documented member or constructor */OverflowException signale un résultat numérique hors de la plage du type cible dans un contexte checked ou une conversion.
Utilisez checked aux frontières où un bouclage numérique corromprait les données.
Toutes les opérations arithmétiques ne lèvent pas d’exception ; les entiers unchecked bouclent.
Nier MinValue ou appeler Abs(MinValue) peut aussi faire déborder un type signed.
Le programme complet utilise réellement System.OverflowException ; sa sortie stdout exacte attendue est OverflowException.
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 { checked { var value = int.MaxValue; value++; } } catch (OverflowException error) { Console.WriteLine(error.GetType().Name); }
Résultat
OverflowException
Le programme complet utilise réellement `System.OverflowException` ; sa sortie stdout exacte attendue est `OverflowException`.