Tracks
/
C#
C#
/
Syllabus
/
Throw Expressions
Th

Throw Expressions in C#

1 exercise

About Throw Expressions

throw expressions are an alternative to throw statements and in particular can add to the power of ternary and other compound expressions.

string trimmed = str == null ? throw new ArgumentException() : str.Trim();

If str is null in the above code an exception is thrown.

Edit via GitHub The link opens in a new window or tab

Learn Throw Expressions