PERL PERL6 INTERNALS 17 HOW TO CHECK AN ATTRIBUTE S EXISTENCE
Date: Thu, 24 Feb 2005 12:05:59 -0700 (MST)

Subject: How to check an attribute's existence
From: cspencer@no-spam (Cory Spencer)

Is is possible to check to see whether an attribute exists on a given object, or at least catch an exception if it doesn't? I've tried to set up an exception handler, but Parrot exits without anything being caught.

A code snippet follows:

.sub _main .local pmc class .local int type .local pmc foo .local pmc val
# The Foo class only has a "bar" attribute.
newclass class, "Foo"
addattribute class, "bar"

# Create a Foo object find_type type, "Foo"
new foo, type
push_eh EXCEPTION
# Try to access the invalid "baz" attribute.
getattribute val, foo, "baz"

end
EXCEPTION:
print "* caught an exception!\n"
end .end

Subject: Re: How to check an attribute's existence
Date: Fri, 25 Feb 2005 08:52:26 +0100

From: lt@no-spam (Leopold Toetsch)
Cory Spencer <cspencer@no-spam> wrote:

> Is is possible to check to see whether an attribute exists on a given > object, or at least catch an exception if it doesn't? I've tried to set > up an exception handler, but Parrot exits without anything being caught.

Not yet. C<getattribute> throws currently an uncatchable internal exception.

leo