Yes, but it should throw the exception to tell you it is out of data.
If you mean it should be rewritten to ensure that it does do that, I agree, it should. It's very random to behave differently depending on whether it runs out of data in the middle of an operation or at the end of one.