Do I need to create my own InvalidArgumentException.. I couldn't find any built-in types in c#... Is there any library which defines commonly used Exception classes.. Thanks
It's called ArgumentException and it's in the built-in System namespace.
Besides ArgumentException
there are also ArgumentNullException
and ArgumentOutOfRangeException
.
Short summary;
System.ArgumentException
- general exception,System.ArgumentNullException
- unexpected null value,System.ArgumentOutOfRangeException
- unexpected value.Standard usage:
void GetEntity(string currentName)
{
if (String.IsNullOrEmpty(currentName))
{
throw new ArgumentNullException(nameof(currentName));
}
//...
}
PS.
NotSupportedException
also comes in handy (e.g. when the set of arguments would force the method to perform not supported scenario).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With