def exception_match(x, y):
    """Check the relation between two given exception `x`, `y`:
    - `x` equals to `y`
    - `x` is a subclass/instance of `y`

    Note that `BaseException` should be considered.

    e.g. `GeneratorExit` is a subclass of `BaseException` but which is not a
    subclass of `Exception`, and it is technically not an error.
    """
    return (
        (issubclass(x, Exception) or issubclass(x, BaseException))
        and issubclass(x, y)
    )