Reputation: 1051
I'm trying to use an exception like in the class below, but the program always fails when I call the kivetel
method. I'd think that it'll just call retry part, than it will satisfy the postcondition. But it fails with "y_above_zero" postcond violation.
class
KEYWORDS
create
make
feature
y:INTEGER
make
do
end
kivetel
do
ensure
y__above_zero: y > 0
rescue
y := 20
retry
end
end
Upvotes: 0
Views: 252
Reputation: 4325
The example shown is not representative for exception handling because of the following reasons:
do
...end
blockkivetel
does nothing, so there cannot be an exception raisedkivetel
is not correct (it does not fulfill the postcondition).So basically your rescue
block is not called, because the exception triggered (postcondition violated) is not raised inside the routine.
Upvotes: 0
Reputation: 703
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).
Upvotes: 5