improve handling of `error_code`
change `exception` into an `error_code`

Don't throw an `exception` if a send or receive file could not be opened. Report that with a corresponding `error_code` instead.