Call can throw, but it is not marked with 'try' and the error is not handled
解决方法:
if fileManager.fileExists(atPath: self.creatFilePath(), isDirectory: &directory){
try? fileManager.createDirectory(atPath: self.creatFilePath(), withIntermediateDirectories: true, attributes: nil)
}
备注
在调用一个函数时,如果发现该函数最后有一个throws,表示该函数可能会抛出异常,处理方式有三种 try try? try!
- try 捕捉异常,并且进行处理
- try? 系统会自动处理异常, 返回一个可选类型(如果有异常则返回一个nil,如果没有异常则返回对应的值)
- try! 告诉系统该函数不会有异常 直接返回值 ps:有异常则程序崩溃(慎用)