最近开始用Ruby进行编程,并且正在寻找异常处理。
想知道是否在C#中ensure的Ruby等价物finally?比如:
file = File.open(""myFile.txt"", ""w"")begin file << ""#{content} \n""rescue #handle the error hereensure file.close unless file.nil?end或者应该这样做?#store the filefile = File.open(""myFile.txt"", ""w"")begin file << ""#{content} \n"" file.closerescue #handle the error hereensure file.close unless file.nil?end相似问题