下面是代码片段(这里的mysql是MySQL for Swift的一个实例):
do {
try mysql.execute("INSERT INTO ...")
} catch {
print(error) // here will print out the actual MySQL error message
return error.localizedDescription // return "The operation couldn’t be completed. (MySQL.Error error 6.)" The real message from the DB is lost.
}在catch部分的第1行中,print语句能够从DB中输出真正的错误消息,但第2行只返回一个通用语句:The operation couldn’t be completed. (MySQL.Error error 6.)
如何从数据库访问带下划线的错误消息?
发布于 2017-04-17 16:42:32
您需要专门捕获MySQLError,以便访问其属性。
} catch let error as MySQLError {
print(error.reason)
}https://github.com/vapor/mysql/blob/master/Sources/MySQL/Error.swift#L8
https://stackoverflow.com/questions/43079475
复制相似问题