Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change EnforcedStyle to standard_error for Lint/InheritException #10407

Merged

Commits on Feb 11, 2022

  1. Change EnforcedStyle to standard_error for Lint/InheritException

    This PR change `EnforcedStyle` from `runtime_error` to `standard_error`
    for `Lint/InheritException`.
    
    I noticed this while investigating rubocop#10406.
    
    Below is the inheritance tree for the exception classes.
    
    ```
    ---------------
    |  Exception  |
    ---------------
          ^
          |
    ---------------
    |StandardError| (default for `rescue`)
    ---------------
          ^
          |
    ---------------
    |RuntimeError | (default for `raise`)
    ---------------
    ```
    
    AFAIK, it seems that custom exceptions generally inherit from `StandardError`.
    Subclasses of `StandardError` are handled with `rescue` by default.
    
    `raise` creates a `RuntimeError` when the exception class is omitted.
    If custom exception inherits from `RuntimeError`, the custom exception
    and `RuntimeError` will be is-a.
    If custom exception inherits from `StandardError`, the custom exception
    and `RuntimeError` will not be is-a.
    In other words, inheriting `StandardError` will not be mistakenly
    handled as `raise` which omits the exception class.
    
    So, inheriting `StandardError` rather than `RuntimeError` does not include
    unnecessary inheritance for `rescue` handling.
    koic committed Feb 11, 2022
    Copy the full SHA
    bb3a8ab View commit details
    Browse the repository at this point in the history