Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / C#

System.Exception: praktična referenca

System.Exception: praktična referenca: Exception je osnova upravljanih pogrešaka i nosi Message, StackTrace te neobvezni InnerException.

Verzija: .NET API; verified on .NET 10.0.14

Sintaksa

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

Exception je osnova upravljanih pogrešaka i nosi Message, StackTrace te neobvezni InnerException.

Bacite konkretniji tip i dodajte kontekst bez gubitka izvorne unutarnje iznimke.

Ne upravljajte logikom preko Message i koristite throw umjesto throw error radi očuvanja stoga.

StackTrace može biti null prije bacanja, a serijalizacija iznimaka nije stabilan protokol među sustavima.

Cijeli program doista koristi System.Exception; točno očekivani stdout jest boom.

Primjeri

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

Rezultat

boom

Cijeli program doista koristi `System.Exception`; točno očekivani stdout jest `boom`.

Izvori