From: Intransition Date: 2012-01-17T01:31:45+09:00 Subject: Safe to reusing the same Exception instance? ------=_Part_843_31220540.1326731502714 Content-Type: multipart/alternative; boundary="----=_Part_844_32970456.1326731502714" ------=_Part_844_32970456.1326731502714 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit This question might be a bit technical with regards to the inner workings of Ruby. (I considered posint to ruby-core) but hopefully here someone will know. Whittling it down to the essentials, I am wondering if it is safe to raise the same error instance multiple times. $ANERROR = RuntimeError.new def foo(var) begin raise $ANERROR, "dynamic message here #{var}" if var.says_so? rescue recorded_errors << var end end The function in itself doesn't matter, that's just a silly example. The main thing is the re-raising of a single instance of the error class, in this example $ANERROR. ------=_Part_844_32970456.1326731502714 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit This question might be a bit technical with regards to the inner workings of Ruby. (I considered posint to ruby-core) but hopefully here someone will know.

Whittling it down to the essentials, I am wondering if it is safe to raise the same error instance multiple times.

    $ANERROR = RuntimeError.new

    def foo(var)
      begin
        raise $ANERROR, "dynamic message here #{var}" if var.says_so?
      rescue
        recorded_errors << var
      end
    end

The function in itself doesn't matter, that's just a silly example. The main thing is the re-raising of a single instance of the error class, in this example $ANERROR.

------=_Part_844_32970456.1326731502714-- ------=_Part_843_31220540.1326731502714--