swift3使用try建立SQLite,抛出“Errors thrown from here are not handle”

按照stephencelis/SQLite.swift的文档,使用try后一直报错,是什么问题?

import SQLite

class CreateSQLiteDB{
    let Sqlite3Path = NSSearchPathForDirectoriesInDomains(
        .documentDirectory, .userDomainMask, true
        ).first! + "/db.sqlite3"
    
    func createSQlite() {
        let db = try Connection(Sqlite3Path)
        let users = Table("users")
        let id = Expression<Int64>("id")
        let name = Expression<String?>("name")
        let email = Expression<String>("email")
        
        try db.run(users.create { t in
            t.column(id, primaryKey: true)
            t.column(name)
            t.column(email, unique: true)
        })
        
    }
}
阅读 3k
1 个回答

先看一下抛出的异常吧,对症下药。
swift 中,try-catch 的用法:


do {
  try expression
} catch let error {
  print(error)
}

Errors thrown from here are not handle 翻译过来就是:这里抛出的异常并未处理

此外,还有 try? 及 try! 。建议稍微去了解一下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题