try catch with multiple exceptions C# code 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: two exceptions same catch c#
try
{
// Code
}
catch (Exception ex) when (ex is ArbitraryType1 || ex is ArbitraryType2)
{
throw;
}