【发布时间】:2016-06-28 16:28:13
【问题描述】:
这可能很容易。我们知道运算符 &+ 对整数进行模运算(回绕),而运算符 + 会导致错误。
$ swift
1> var x: Int8 = 100
x: Int8 = 100
2> x &+ x
$R0: Int8 = -56
3> x + x
Execution interrupted. Enter Swift code to recover and continue.
这是什么错误?我无法抓住它,也无法将其转换为可选:
4> do {try x + x} catch {print("got it")}
Execution interrupted. Enter Swift code to recover and continue.
5> try? x + x
Execution interrupted. Enter Swift code to recover and continue.
我很确定这种错误与this Stack Overflow question 中的错误相同(被零除),但我不知道这种错误是否可以被捕获。我错过了什么简单的事情?能不能被困住?如果有,怎么做?
【问题讨论】:
标签: swift error-handling integer-overflow