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

 初吻给了烟200309 发布于 2022-10-27 18:24

按照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("id")
        let name = Expression("name")
        let email = Expression("email")
        
        try db.run(users.create { t in
            t.column(id, primaryKey: true)
            t.column(name)
            t.column(email, unique: true)
        })
        
    }
}
1 个回答
  • 先看一下抛出的异常吧,对症下药。
    swift 中,try-catch 的用法:

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

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

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

    2022-10-29 01:57 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有