Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.OverflowException: referencia práctica

System.OverflowException: referencia práctica: OverflowException señala un resultado numérico fuera del intervalo del tipo destino en un contexto checked o una conversión.

Versión: .NET API; verified against .NET 10 reference surface

Sintaxis

System.OverflowException /* select a documented member or constructor */

OverflowException señala un resultado numérico fuera del intervalo del tipo destino en un contexto checked o una conversión.

Usa checked en límites donde el desbordamiento circular corrompería datos.

No toda aritmética lanza una excepción; los enteros unchecked se desbordan de forma circular.

Negar MinValue o llamar a Abs(MinValue) también puede desbordar un tipo signed.

El programa completo usa realmente System.OverflowException; su stdout esperado exacto es OverflowException.

Ejemplos

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

El programa completo usa realmente `System.OverflowException`; su stdout esperado exacto es `OverflowException`.

Fuentes