- Published on
C# - 6.0 Exception Filters
Before C# 6
static void Main ( string [ ] args )
{
try
{
doSomething();
}
catch (Exception ex)
{
if (ex.Message == "DataNotFount")
{
Console.WriteLine("DataNotFount");
}
else if (ex.Message == "ChangePasswordError")
{
Console.WriteLine("ChangePasswordError");
}
}
}
C# 6
static void Main ( string [ ] args )
{
try
{
doSomething();
}
catch (Exception ex) when (ex.Message == "DataNotFount")
{
Console.WriteLine("DataNotFount");
}
catch (Exception ex) when (ex.Message == "ChangePasswordError")
{
Console.WriteLine("ChangePasswordError");
}
}