Throwing exceptions in expressions in C# 7.0
January 15, 2018 Leave a comment
C# 7.0 makes it possible to throw exceptions with ternary and null-coalescing operators.
Here’s an example where we throw an exception if the divisor is 0:
private double Divide(double what, double withWhat) { return withWhat != 0 ? what / withWhat : throw new ArgumentException("nono"); }