C# exception filter?

前端 未结 4 1779
北恋
北恋 2020-12-10 04:04

Does C# support compiling filters? How do filters even work or what do they do?

Like reflector decompiles a filter as

try
{
}
catch(Exception e) when (?)
{         


        
4条回答
  •  时光说笑
    2020-12-10 04:25

    Exception filters support in C# is introduced in C# 6 (Visual Studio "Dev14"):

    try
    {
        throw new ApplicationException("1");
    }
    catch (ApplicationException ex) when (ex.Message == "2")
    {
        // this one won't execute.
    }
    catch (ApplicationException ex) when (ex.Message == "1")
    {
        // this one will execute
    }
    

提交回复
热议问题