Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Exception: praktická referencia

System.Exception: praktická referencia: Exception je základom spravovaných chýb a nesie Message, StackTrace a voliteľnú InnerException.

Verzia: .NET API; verified on .NET 10.0.14

Syntax

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

Exception je základom spravovaných chýb a nesie Message, StackTrace a voliteľnú InnerException.

Vyhadzujte konkrétnejší typ a pridajte kontext bez straty pôvodnej vnútornej výnimky.

Neriaďte logiku textom Message a použite throw namiesto throw error na zachovanie zásobníka.

StackTrace môže byť pred vyhodením null a serializácia výnimiek nie je stabilný protokol medzi systémami.

Úplný program skutočne používa System.Exception; presne očakávaný stdout je boom.

Príklady

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);

Výsledok

boom

Úplný program skutočne používa `System.Exception`; presne očakávaný stdout je `boom`.

Zdroje