Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Exception: odniesienie praktyczne

System.Exception: odniesienie praktyczne: Exception jest bazą zarządzanych błędów z Message, StackTrace i InnerException.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

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

Exception jest bazą zarządzanych błędów z Message, StackTrace i InnerException.

Rzucaj bardziej konkretny typ i dodawaj kontekst bez utraty wyjątku wewnętrznego.

Nie steruj logiką Message; użyj throw zamiast throw error, by zachować stos.

StackTrace może być null przed rzuceniem; serializacja wyjątków nie jest stabilnym protokołem.

Kompletny program rzeczywiście używa System.Exception; oczekiwany stdout to dokładnie boom.

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;

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

Wynik

boom

Kompletny program rzeczywiście używa `System.Exception`; oczekiwany stdout to dokładnie `boom`.

Źródła