ruby picture

RCR 271: ignoring raise exceptions (supressing all errors)

Submitted by mig (Wed Aug 04 05:08:04 UTC 2004)

Abstract

I have method with many "raise". I want to call it and herewith supress any errors (ignore these raises).

Problem

It would be useful when you have a method which is called at once by user and internally. If internally, you need to supress testings and force it.

def foo
   raise "account already exist" if bla
   raise "account..." if bla
   create_account
end

Nowadays I must do it like this (which makes code less readable and larger):

def foo
   unless @force
      raise "account already exist" if bla
      raise "account..." if bla
   end
   create_account
end

Proposal

I think this could be an elegant solution:

begin
  my_method
rescue
  ignore
end

Ignore would act as continue of raise, you'll be able to do some stuff and then return back.

Analysis

Implementation

ruby picture
Comments Current voting
Strongly opposed 0
Opposed 0
Neutral 0
In favor 0
Strongly advocate 0
ruby picture

This RCR has been superseded by RCR 272.

ruby picture

Powered by .