Pro EP 57: How to throw exceptions based on NULL values in .NET ?

Muhammad Waseem
Become .NET Pro !
Aug 21, 2023

Previously we used to check first if the value is null and then throw exception but with .NET 6 and since C# 11 we can do these both things in one go

Although there is no issue with first approach but now we can use ThrowIfNull Method which is more concise less code.

Whenever you’re ready, there are 4 ways I can help you

  1. Subscribe to my Weekly .NET Newsletter of C#/.NET with 7000+ Software Engineers.
  2. Promote yourself to 7000+ subscribers by Sponsoring my Newsletter
  3. Download my eBook at Gum Road which contains 30+ .NET Tips (With 2800+ Downloads)
  4. To get 100+ free and paid resources for learning C# and .NET visit this GitHub Repository

--

--