Skip to content

inherit-exception

Rubysuspiciousno fixdefault: offruby/rubocop

Reports a class that inherits Exception directly (class A < Exception, Class.new(Exception)).

A plain rescue catches StandardError and its subclasses only. An exception that inherits Exception is not caught by it, and it is also not caught by code that handles all normal errors, so it ends the program, as does exit.

To fix, inherit from StandardError.

Reported
class A < Exception; end
class B < StandardError
...
super(msg)
...
ruby:
lint:
rules:
inherit-exception: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line inherit-exception in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/InheritException full