catch multiple exceptions c# example
Example 1: c# try catch multiple catches
try
{
Console.WriteLine("Chose a number: ");
int usrNo = Convert.ToInt32(Console.ReadLine());
return usrNo;
}
catch (FormatException ex)
{
ErrorMessagePrintCustomMessage("You pressed a letter");
}
catch (Exception ex) { ErrorMessageErrorOccured(ex); }
Example 2: c# multiple catch exceptions
// if C# v6+, you can use exception filters
catch (Exception ex) when (ex is FormatException || ex is OverflowException)
{
// do something
}