'Installs a replacement for sys.excepthook, which handles pretty-printing uncaught exceptions.'

def _install_exception_handler(self):

    if six.PY2:
        sys.stderr = codecs.getwriter('utf-8')(sys.stderr)
    def handler(t, value, traceback):
        if self.args.verbose:
            sys.__excepthook__(t, value, traceback)
        elif (t == UnicodeDecodeError):
            sys.stderr.write(('Your    file    is    not    "%s"    encoded.    Please    specify    the    correct    encoding    with    the    -e    flag.    Use    the    -v    flag    to    see    the    complete    error.\n' % self.args.encoding))
        else:
            sys.stderr.write(('%s\n' % six.text_type(value)))
    sys.excepthook = handler
