Add error handling for all stream methods that take a function.

Partly solves #94.