CKTIS / C#
System.OverflowException: praktická referencia
System.OverflowException: praktická referencia: OverflowException hlási číselný výsledok mimo rozsahu cieľového typu v kontexte checked alebo pri konverzii.
Verzia: .NET API; verified against .NET 10 reference surface
Syntax
System.OverflowException /* select a documented member or constructor */OverflowException hlási číselný výsledok mimo rozsahu cieľového typu v kontexte checked alebo pri konverzii.
Použite checked na hraniciach, kde by pretečenie s obtočením poškodilo údaje.
Nie každá aritmetika vyhodí výnimku; celočíselné operácie unchecked sa obtočia.
Negácia MinValue alebo volanie Abs(MinValue) môže tiež pretiecť pri type signed.
Úplný program skutočne používa System.OverflowException; presne očakávaný stdout je OverflowException.
Príklady
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); }
Výsledok
OverflowException
Úplný program skutočne používa `System.OverflowException`; presne očakávaný stdout je `OverflowException`.