Check stream is open before writing rather than waiting for exception