CKTIS / C#
throw: praktična referenca
throw: praktična referenca: throw sproži izjemo; samostojni throw v catch jo znova sproži z ohranjenim skladom.
Različica: C# language; verified against C# 14 reference
Sintaksa
throw /* grammar-specific form */throw sproži izjemo; samostojni throw v catch jo znova sproži z ohranjenim skladom.
Uporabite določeno izjemo za kršitev, ki je trenutna funkcija ne more obravnavati.
throw ex ponastavi vidno mesto, izjeme pa ne smejo voditi običajnega toka.
Izraz throw je lahko v ?? ali ?:; met null povzroči NullReferenceException.
Celoten program dejansko uporabi throw; natančno pričakovani stdout je boom.
Primeri
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); }
Rezultat
boom
Celoten program dejansko uporabi `throw`; natančno pričakovani stdout je `boom`.