Factor out the code handling the exception in a separate function for
easier testing and adjusting unit test acordingly.

- Factor out error handling into own function cli.handle_error
- Adjust unit test to raise exception and hand it to handle_error
- Define expected output on stderr as heredoc