CKTIS / C#
throw: praktická reference
throw: praktická reference: throw vyhodí výjimku; samotné throw v catch ji vyhodí znovu se zachovaným stackem.
Verze: C# language; verified against C# 14 reference
Syntaxe
throw /* grammar-specific form */throw vyhodí výjimku; samotné throw v catch ji vyhodí znovu se zachovaným stackem.
Použijte konkrétní výjimku pro porušení, které aktuální funkce nedokáže obsloužit.
throw ex přepíše viditelné místo vyhození a výjimky nemají řídit běžný tok.
Výraz throw může být v ?? či ?:; vyhození null způsobí NullReferenceException.
Úplný program skutečně používá throw; přesně očekávaný stdout je boom.
Pří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;
try { throw new Exception("boom"); } catch (Exception error) { Console.WriteLine(error.Message); }
Výsledek
boom
Úplný program skutečně používá `throw`; přesně očekávaný stdout je `boom`.