[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Is there any way to throw an exception in a finalizer?

sera

11/19/2003 11:51:00 PM

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?

Thanks in advance,

Francis
1 Answer

matz

11/20/2003 8:00:00 AM

0

Hi,

In message "Is there any way to throw an exception in a finalizer?"
on 03/11/20, Francis Hwang <sera@fhwang.net> 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.