Re: Login controller additions

Nicholas Seckar
Sat, 12 Mar 2005 19:33:50 -0000

On Saturday 12 March 2005 11:18, Marcel Molina Jr.
wrote:
> Though don''t use rescue cavalierly. You could cover up what might
be an
> unrelated exception.

If you''re both lazy and worried about unrestricted rescues, use
supress:

class Object
  def suppress(*exc_classes)
    begin return yield
    rescue Object => e
      raise unless exc_classes.any? {|cls| e.kind_of? cls}
    end
  end
end

suppress {raise ArgumentError} # raises argument error past suppress
suppress(ArgumentError) {raise ArgumentError} # returns nil
suppress(ArgumentError) { 2 } # returns 2

--

Nicholas Seckar aka. Ulysses