CKTIS / C#
System.OverflowException: riferimento pratico
System.OverflowException: riferimento pratico: OverflowException segnala un risultato numerico fuori dall’intervallo del tipo destinazione in un contesto checked o in una conversione.
Versione: .NET API; verified against .NET 10 reference surface
Sintassi
System.OverflowException /* select a documented member or constructor */OverflowException segnala un risultato numerico fuori dall’intervallo del tipo destinazione in un contesto checked o in una conversione.
Usa checked ai confini in cui il riavvolgimento numerico corromperebbe i dati.
Non tutte le operazioni aritmetiche generano eccezioni; gli interi unchecked si riavvolgono.
Negare MinValue o chiamare Abs(MinValue) può causare overflow anche per un tipo signed.
Il programma completo usa realmente System.OverflowException; lo stdout esatto atteso è OverflowException.
Esempi
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); }
Risultato
OverflowException
Il programma completo usa realmente `System.OverflowException`; lo stdout esatto atteso è `OverflowException`.