问题描述:

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. ​

相关阅读:
Top