0

我正在尝试使用下面类中的异常,但是当我调用该kivetel方法时程序总是失败。我认为它只会调用重试部分,而不是满足后置条件。但它因违反“y_above_zero”而失败。

class
KEYWORDS
create
    make
feature
    y:INTEGER

make
do
end

kivetel
do
ensure
    y__above_zero: y > 0
rescue
    y := 20
    retry
end
end
4

2 回答 2

5

This is the expected behavior when you run it under EiffelStudio, i.e under the debugger. If you run it outside ... from the console for instance, you won't notice anything, the execution will go through the rescue clause and retry and continue as expected.

But under debugger, anytime there is an assertion violation, or an exception, the debugger will catch it and popup the dialog.

(note this is possible to ignore specific kind of exception, if this is really bothering you).

于 2014-01-09T13:43:23.040 回答
0

由于以下原因,所示示例不能代表异常处理:

  1. ...块中没有引发异常doend
  2. 例程kivetel什么都不做,所以不会引发异常
  3. 例程kivetel不正确(它不满足后置条件)。

所以基本上你的rescue块不会被调用,因为触发的异常(违反后条件)不会在例程中引发。

于 2020-04-11T23:16:06.527 回答