Catch exceptions when reading rational number ended with eof

Previously, operator>> crashes when reading a (valid) rational number
that ends with eof. This patch fixes the problem.