This page is no longer maintained — Please continue to the home page at

failure tolerant iteration

No replies
Joined: 2009-10-23,
User offline. Last seen 1 year 37 weeks ago.

Hello scalaists

I came across this some days ago - trying to use scala like I would use perl

val input ="./test.txt").getLines

One of the textfiles I was trying to process contained a malformed UTF8-
Symbol. So the foreach() broke down with an exception.

The only obvious solution to this (apart from not processing the malformed
file - which is unfortunately not an option) seems to be to hand craft the
whole textstream-reading and UTF8-conversion stuff to be able to get over the
malformed line and continue the text processing...

But as it is not that unusual to be forced to process some input "as good and
complete as possible" (i.e. error tolerant) I wonder if we could have
something like a failure tolerant iterable version for input processing.

something along (for this use case)
getLinesTolerant() : Iterator[Either[String, RecoverableException]]
getLinesTolerant() : Iterator[(Option[String], Option[RecoverableException])]

with the semantic that it fails with an exception if something happens that
does not allow for a next iteration step (i.e. source file is no longer
available) otherwise it either reports the result or the error data to the
consuming client and allows the client to proceed along with its processing.

This would enhance the usability for scala as a simple and straightforward
processing language.

[to be honest I switched back to perl for now as this kind of stuff is still a
bit too heavy lifting for my limited scala know how - and I just had to get
the stuff done...]

how do you think about this?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland