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

前端 未结 10 1699
青春惊慌失措
青春惊慌失措 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:04

    Why not just change it to

    int foo(int x, y)
    {
        if (y == 0)
            throwException("Doh!");
        return x/y;
    }
    

    This gives the same runtime results, and the compiler won't complain.

提交回复
热议问题