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

raise shorthand #526

Closed
chriseppstein opened this issue Sep 30, 2013 · 4 comments
Closed

raise shorthand #526

chriseppstein opened this issue Sep 30, 2013 · 4 comments
Assignees

Comments

@chriseppstein
Copy link

Ruby allows raise <ExceptionType>, <message> which it then translates into raise <ExceptionType>.new(<message>).

I think most people prefer the former, but my project prefers the latter. I think there should be a cop that enforces one or the other and which form should be configurable.

@ghost ghost assigned bbatsov Oct 1, 2013
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 1, 2013

Sure, that makes sense.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 1, 2013

Btw, what about the scenario when raise is called with 3 arguments - raise ExceptionClass, message, backtrace? AFAIK you cannot pass the backtrace to the Exception constructor, so that would introduce an inconsistency. Or I just might be missing something.

@jonas054
Copy link
Collaborator

jonas054 commented Oct 3, 2013

I guess the specific exception class being raised could take a backtrace argument and call set_backtrace internally, but RuboCop can't be expected to know that. So I say you should allow raise with 3 arguments, or possibly have a configuration parameter called AllowRaiseWithThreeArguments or something, trueby default.

@chriseppstein
Copy link
Author

That's fine. It's a very rare thing to do. We use set_backtrace and the single argument version.

@bbatsov bbatsov closed this as completed in bca6286 Oct 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants