Skip to content

Commit

Permalink
Clarify that you can raise exceptions without arguments
Browse files Browse the repository at this point in the history
Whilst `MyCustomError.new` violates this Rubocop rule, the documentation implies the only way of fixing it is to pass an argument representing the exception message, whereas actually if your custom exception has a default message, it's quite possible you just want to use the default message. This can be achieved without violating this Rubocop rule, by omitting the call to `.new`.
  • Loading branch information
ChrisBAshton authored and bbatsov committed Jun 11, 2021
1 parent a20493d commit 9584b01
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rubocop/cop/style/raise_args.rb
Expand Up @@ -23,6 +23,7 @@ module Style
# # good
# raise StandardError, 'message'
# fail 'message'
# raise MyCustomError
# raise MyCustomError.new(arg1, arg2, arg3)
# raise MyKwArgError.new(key1: val1, key2: val2)
#
Expand All @@ -37,6 +38,7 @@ module Style
#
# # good
# raise StandardError.new('message')
# raise MyCustomError
# raise MyCustomError.new(arg1, arg2, arg3)
# fail 'message'
class RaiseArgs < Base
Expand Down

0 comments on commit 9584b01

Please sign in to comment.