Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / C#

System.Exception: riferimento pratico

System.Exception: riferimento pratico: Exception è la base degli errori gestiti e contiene Message, StackTrace e un’eventuale InnerException.

Versione: .NET API; verified on .NET 10.0.14

Sintassi

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

Exception è la base degli errori gestiti e contiene Message, StackTrace e un’eventuale InnerException.

Genera un tipo più specifico e aggiungi contesto senza perdere l’eccezione interna originale.

Non guidare la logica con Message e usa throw anziché throw error per preservare lo stack.

StackTrace può essere null prima del lancio e la serializzazione delle eccezioni non è un protocollo stabile tra sistemi.

Il programma completo usa realmente System.Exception; lo stdout esatto atteso è boom.

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;

var error = new Exception("boom");
Console.WriteLine(error.Message);

Risultato

boom

Il programma completo usa realmente `System.Exception`; lo stdout esatto atteso è `boom`.

Fonti