Return statements in catch blocks

后端 未结 6 1551
渐次进展
渐次进展 2021-01-13 05:29

I have seen some developers use the return statement in a catch block. Why/when would this be a useful technique to employ?

EDIT: I actually just saw the return keyw

6条回答
  •  我在风中等你
    2021-01-13 06:08

    There are occasions when you do not care about the exception thrown, only that the Try operation failed. An example would be the TryParse functions which in pseduo code look like:

    try
    {
       //attempt conversion
       return true;
    }
    catch
    {
       return false;
    }
    

提交回复
热议问题