Return statements in catch blocks

后端 未结 6 1536
渐次进展
渐次进展 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:23

    Any situation where you have an alternative if the attempt fails. An example could be checking if file is available for some operation

        bool IsComplete = false;
    
        try
        {
          //  FileStream currentWriteableFile = 
                         File.OpenWrite(sFileLocation);          
        }
        catch(Exception)
        {
          return false;
        }
    

提交回复
热议问题