当前位置: 动力学知识库 > 问答 > 编程问答 >

groovy - Store the assert failure result in a variable

问题描述:

I'm new to groovy and I have doubt. Lets say I have this statement:

assert "king" == "kin"

which will give me the assert failure as

Assertion failed:

assert "king" == "kin"

|

false

and stops the program. But what I want is, store the result (the failure message, if any say in GString) and proceed with the program.

Is that possible to do so?

网友答案:

You can catch the AssertionError exception. Something like this:

try {
  assert ["hello"] == ["A"]
}
catch(AssertionError e) {
  result = e.getMessage()
}
println  result

This should work. ​

分享给朋友:
您可能感兴趣的文章:
随机阅读: