Is there a standard “never returns” attribute for C# functions?

前端 未结 10 1657
青春惊慌失措
青春惊慌失措 2020-12-03 20:42

I have one method that looks like this:

void throwException(string msg)
{
    throw new MyException(msg);
}

Now if I write

         


        
10条回答
  •  温柔的废话
    2020-12-03 21:13

    The [DoesNotReturn] attribute in System.Diagnostics.CodeAnalysis should be what you want.

    Reference: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.doesnotreturnattribute?view=netcore-3.1

提交回复
热议问题