提问人:LiangOla 提问时间:9/11/2023 最后编辑:NerkyatorLiangOla 更新时间:9/11/2023 访问量:33
Swift 处理自定义错误,但有问题
Swift Handling Custom Error but something wrong
问:
这是我的自定义错误
public struct CSHttpError: Error {
enum CSHttpErrorScene {
case clientRequestError
case customError
}
let code: Int?
let kind: CSHttpErrorScene
let description: String?
init(code:Int?,kind:CSHttpErrorScene,description:String?) {
self.code = code
self.kind = kind
self.description = description ?? ""
}
}
当发布请求并获取空数据时 我想用CSHttpError抛出这个错误
let error = CSHttpError(code: -1, kind: .clientRequestError, description:"No Response Data")
throw error
但是当我发现此错误时,“描述”和“代码”丢失了
...
} catch let error as CSHttpError {
print(error.description) // Optional("The operation couldn’t be completed. (VHK.CSHttpError error 1.)")
print(error.kind) // .clientRequestError
throw VHKError.network(error)
}
error.description 应为“无响应数据”????
我尝试调试它,但它不起作用
答: 暂无答案
评论