当我运行以下代码时,我得到了异常,这没关系,因为字符串 [0] 是“1”而不是 2
所以断言产生这个异常并从代码中中断......。
但我想做的是:
是在 assert string[0] 不是 1 的情况下打印NOT equal ,并忽略异常
别的
如果字符串 [0] 为 1
然后代码将打印相等
string = "1 2 3"
assert string[0] == '2'
println "continue"
.
Exception thrown
Assertion failed:
assert string[0] == '2'
| | |
1 2 3 1 false