Open sebthom opened 8 years ago
The current behavior is especially tiring because a try/finally clause doesn't exist (yet) in Haxe. So to read all lines one-by-one properly, atm in Haxe one would have to do:
static function main() {
var is = sys.io.File.read("test.txt", false);
try {
while (true) {
trace(is.readLine());
}
} catch (e: Eof) {
// expected
is.close();
} catch (e: Dynamic) {
is.close();
#if neko neko.Lib.rethrow #else throw #end (e);
}
}
That is a lot of boiler plate code and exception driven flow-control is really bad coding practice!
readLine catches Eof and then does this:
if( s.length == 0 )
#if neko neko.Lib.rethrow #else throw #end (e);
This code is ancient so I'll not touch it for 3.3, but I agree something is wrong here.
This relates to #3611: --interp fileInput.eof() bug.
FileInput.eof()
follows the behavior of C's feof
and "only returns true if we tried to read past the file end."
The following code fails on all sys targets with an EOF exception, but shouldn't because before invoking readLine the EOF status is tested.
The example works if
is replaced by