throw string exception c# code example
Example 1: c# throw new exception
static void CopyObject(SampleClass original)
{
if (original == null)
{
throw new System.ArgumentException("Parameter cannot be null", "original");
}
}
Example 2: trhow exception if is null c#
var firstName = name ?? throw new ArgumentException("Mandatory parameter", nameof(name),);