Stream class: better error handling.