Catch all exceptions in C#
Forums:
class IsNullException : Exception { }
class IsEmptyException : Exception { }
void ThrowWhenNullOrEmpty(List<int> list)
{
if (list == null) {
throw new IsNullException();
}
if (list.Count == 0) {
throw new IsEmptyException();
}
}
try {
ThrowWhenNullOrEmpty(null);
}
catch {
Console.WriteLine("Error happened");
}
- Log in to post comments