CKTIS / C#
System.OverflowException: odniesienie praktyczne
System.OverflowException: odniesienie praktyczne: OverflowException sygnalizuje wynik liczbowy poza zakresem docelowego typu w kontekście checked lub konwersji.
Wersja: .NET API; verified against .NET 10 reference surface
Składnia
System.OverflowException /* select a documented member or constructor */OverflowException sygnalizuje wynik liczbowy poza zakresem docelowego typu w kontekście checked lub konwersji.
Stosuj checked na granicach, gdzie zawinięcie liczby byłoby uszkodzeniem danych.
Nie każda arytmetyka zgłasza wyjątek; unchecked typy całkowite zawijają się.
MinValue negowane lub Abs(MinValue) także może przepełnić typ signed.
Kompletny program rzeczywiście używa System.OverflowException; oczekiwany stdout to dokładnie OverflowException.
Przykłady
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); }
Wynik
OverflowException
Kompletny program rzeczywiście używa `System.OverflowException`; oczekiwany stdout to dokładnie `OverflowException`.