CKTIS / C#
throw: praktična referenca
throw: praktična referenca: throw baca iznimku; samostalni throw u catch ponovno je baca uz očuvan stog.
Verzija: C# language; verified against C# 14 reference
Sintaksa
throw /* grammar-specific form */throw baca iznimku; samostalni throw u catch ponovno je baca uz očuvan stog.
Koristite određenu iznimku za kršenje koje trenutačna funkcija ne može obraditi.
throw ex poništava vidljivo mjesto bacanja, a iznimke ne trebaju voditi uobičajeni tok.
Izraz throw može biti u ?? ili ?:; bacanje null daje NullReferenceException.
Cijeli program doista koristi throw; 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;
try { throw new Exception("boom"); } catch (Exception error) { Console.WriteLine(error.Message); }
Rezultat
boom
Cijeli program doista koristi `throw`; točno očekivani stdout jest `boom`.