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

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

    Don't hand the exception creation off to another function (i.e. just throw it directly) and the compiler won't complain. Handing off to a "helper" type function for exception throwing is a waste of time unless the function is actually adding value to the exception process.

提交回复
热议问题