throw

A statement that deliberately raises an exception object.

What does throw do in C#?

throw — A statement that deliberately raises an exception object.

class Reservation
{
    void Reserve(int seats)
    {
        if (seats < 1)
        {
            throw new ArgumentException("Seat count must be positive");
        }
    }
}

Level: Journeyman · More C# terms at this level

Updated

In other subjects