c# multiple catch exceptions
// if C# v6+, you can use exception filters
catch (Exception ex) when (ex is FormatException || ex is OverflowException)
{
// do something
}
c# multiple catch exceptions
// if C# v6+, you can use exception filters
catch (Exception ex) when (ex is FormatException || ex is OverflowException)
{
// do something
}
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); }
catch multiple exception c#
catch (Exception ex)
{
if (ex is FormatException || ex is OverflowException)
{
WebId = Guid.Empty;
return;
}
throw;
}
c# catch two exceptions in one block
catch (Exception ex)
{
if (ex is FormatException || ex is OverflowException)
{
WebId = Guid.Empty;
return;
}
throw;
}
c# catch multiple exceptions at once
catch (Exception ex)
{
if (ex is FormatException or OverflowException) // Chain as many or xException as you need
{
WebId = Guid.Empty;
return;
}
throw;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us