docs: def check_returncode(p, out):
      """Raise exception according to unrar exit code.
      """
      code = p.returncode
      if code == 0:
          return
  
      # map return code to exception class, codes from rar.txt
      errmap = [None,
                RarWarning, RarFatalError, RarCRCError, RarLockedArchiveError,    # 1..4
                RarWriteError, RarOpenError, RarUserError, RarMemoryError,        # 5..8
                RarCreateError, RarNoFilesError, RarWrongPassword]                # 9..11
      if UNRAR_TOOL == ALT_TOOL:
          errmap = [None]
      if code > 0 and code < len(errmap):
          exc = errmap[code]
      elif code == 255:
          exc = RarUserBreak
      elif code < 0:
          exc = RarSignalExit
      else:
          exc = RarUnknownError
  
      # format message
      if out:
          msg = "%s [%d]: %s" % (exc.__doc__, p.returncode, out)
      else:
          msg = "%s [%d]" % (exc.__doc__, p.returncode)
  
      raise exc(msg)