I suspect the problem is in some code you didn't show us. Why? See the code at the bottom of this post. When I make your code compilable and
test the logic it runs as expected. So here is what
you should do:
1) Tell us exactly how it doesn't work. Do you get an exception, does the program crash? What exactly is the behavior, and how does that contrast with what you expect to happen?
2) Show us the real code. Make a small, compilable, demonstration application that misbehaves the same way your real code does, and show us this sample (it is called making a
SSCCE. Who knows, perhaps in the process of making the
SSCCE you will find the error and fix it.
My example SSCCE based on your code.
Expect it to report failure 2 times, then succeed on the third.
Results:
Code:
>