C# 6 has a new feature called "exception filtering"
The syntax is like this:
catch (Win32Exception exception) when (exception.NativeErrorCode == 0x00042)
{
//Do something here
}
I couldn't help but wonder what the benefit of that is over the current approach:
catch (Win32Exception exception)
{
if (exception.NativeErrorCode == 0x00042)
{
//Do something here
}
}
Is it a big deal that filtering happen before the curly bracket? Perhaps in relation to performance or security?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…