C# exception filter?

前端 未结 4 1898
北恋
北恋 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:11

    Since C# 6 you can now do this.

    try { … }
    catch (MyException e) when (myfilter(e))
    {
        …
    }
    

    This is different from using an if statement from within the catch block, using exception filters will not unwind the stack.

提交回复
热议问题