From: matz@... (Yukihiro Matsumoto) Date: 2003-11-20T16:59:40+09:00 Subject: Re: Is there any way to throw an exception in a finalizer? Hi, In message "Is there any way to throw an exception in a finalizer?" on 03/11/20, Francis Hwang writes: |I'm trying to do write test code that involves a mock object throwing |an exception on object destruction if a certain condition isn't met. |(In particular, I want to guarantee that a class that uses DBI calls |@dbh.disconnect.) I've been trying to set a finalizer with |ObjectSpace.define_finalizer, but it seems like the GC doesn't want me |to raise an exception from within a finalizer. Overall I understand -- |I probably wouldn't try anything this gnarly in production code -- but |is there any way for me to get around this for test code? You cannot assume when and where finalizers are called, and they are not guaranteed to be called. I don't think it's a good idea to raise exception from within finalizers. matz.