函数后缀含义throws的方法调用
来源:互联网 发布:百旺税控盘开票软件 编辑:程序博客网 时间:2024/06/03 21:11
Swift 使用throws抛出异常使用方法:
我在开发中遇到带有抛出异常的关键字throws标注的方法,直接调用会报错,具体如下:
函数:
public func createDirectoryAtPath(path: String, withIntermediateDirectories createIntermediates: Bool, attributes: [String : AnyObject]?) throws
调用:
搜索: Call can throw, but it is not marked with 'try' and the error is not handled未能找到我要的结果,
在网上查阅一下资料,发现swift版本更新之前时 ,代码:
fileManager.createDirectoryAtPath(mydir2, withIntermediateDirectories: true, attributes: nil, error: &error)
swift更新之后 ,使用throws抛出异常,具体调用代码如下:
do {
try fileManager.createDirectoryAtPath(mydir1, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
print(error.description)
}
格式:
do {
try 调用函数
} catch 定义异常变量 类型 {
处理异常
}
- 函数后缀含义throws的方法调用
- throws,throw,try,catch,finally的含义
- MAX232后缀的含义
- PackageManagerService中LI,LP等函数后缀的含义
- c++,dll后缀的控件调用主程序本身的函数方法
- 【RuntimeException运行时异常】方法不需要throws、调用该方法的程序不需要try-catch
- EBS 表后缀的含义
- ATmega单片机后缀的含义
- 常用域名后缀的含义
- 函数的调用方法
- 有关方法的throws异常理解
- JavaScript中七种函数调用方式及对应 this 的含义
- JavaScript中七种函数调用方式及对应 this 的含义
- JavaScript中七种函数调用方式及对应 this 的含义
- JavaScript中七种函数调用方式及对应 this 的含义
- 关于rpm的后缀devel的含义
- mfc工程各后缀文件的含义
- Quartus II工程文件的后缀含义
- mysql 5.7 插入中文数据变?乱码问题
- 根据访问地址截取根路径
- jquery 绘图工具 flot 学习笔记
- JAVA 线程
- 使用cnpm
- 函数后缀含义throws的方法调用
- android设置app支持多语言
- easyui-combobox多选-样式改为checkbox
- simple-spa 一个简单的单页应用实例
- Idea导入项目后 Manifest首行红色 提示URI is not registered
- 编程思想总结
- 07--C++中引用的本质思考
- unix/Linux常用命令英文全称与中文解释 man ,su,ps,ls 等等
- JS闭包