From: Robert Klemme Date: 2010-03-24T06:45:28+09:00 Subject: Re: what's the suggested raise Exception idiom? On 03/23/2010 06:22 PM, Nathan Beyer wrote: > What's the distinction between: > raise ArgumentError, "the argument was invalid" > and > raise ArgumentError.new("the argument was invalid") > > How does this apply in the case of exceptions with custom initializers > for attributes? For example: > class StatusCodeError < StandardError > attr_reader :status_code > def initialize(status_code) > @status_code = status_code > end > end > > I've been reading a lot of code, books and blogs, but haven't gotten > as clear of an understanding on why people choose one way over > another, so I'm looking for additional opinions and commentary. I believe raise a,b,c,d... is merely syntactig sugar for raise a.new(b,c,d...) with a bit of added functionality (e.g. if a is not an exception class there is an error, if a is a String a StandardError is raised). To answer your question, normally there is no reason to use a variant with "new" - rather save yourself a bit of typing and use the shorter form. My 0.02EUR. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/