exceptionrescueeiffelpost-conditions

Eiffel exception not work


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

Solution

  • 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).