CKTIS / C#
System.OverflowException: referência prática
System.OverflowException: referência prática: OverflowException assinala um resultado numérico fora do intervalo do tipo de destino num contexto checked ou numa conversão.
Versão: .NET API; verified against .NET 10 reference surface
Sintaxe
System.OverflowException /* select a documented member or constructor */OverflowException assinala um resultado numérico fora do intervalo do tipo de destino num contexto checked ou numa conversão.
Usa checked nos limites onde o retorno circular do número corromperia dados.
Nem toda a aritmética lança uma exceção; operações inteiras unchecked dão a volta.
Negar MinValue ou chamar Abs(MinValue) também pode exceder um tipo signed.
O programa completo usa realmente System.OverflowException; o stdout exato esperado é OverflowException.
Exemplos
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); }
Resultado
OverflowException
O programa completo usa realmente `System.OverflowException`; o stdout exato esperado é `OverflowException`.