Swift Try Catch问题

时间:2017-08-07 15:24:18

标签: swift try-catch nsexception

我是Swift的新手..我正在尝试尝试捕捉,以确保当我尝试从我的tableview和我的notes数组中删除一行时,我不会遇到任何问题。

这是代码

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

    do{
        try removerowtableview(indexPath: indexPath)
    }catch{
            print(error.localizedDescription)
    }
}


func removerowtableview(indexPath: IndexPath) throws{

    dataModel.notas.remove(at: 1000) //1000 to force to crash

    self.tableView.deleteRows(at: [indexPath as IndexPath], with: UITableViewRowAnimation.fade)

    dataModel.saveData()
}

dataModel.notas是我的笔记数组,我希望它不会崩溃应用程序并打印错误,但我得到terminating with uncaught exception of type NSException。为什么?我做错了什么?

提前致谢并对一些英语错误感到抱歉。

0 个答案:

没有答案
相关问题