Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check an attribute's existence

14 views
Skip to first unread message

Cory Spencer

unread,
Feb 24, 2005, 2:05:59 PM2/24/05
to perl6-i...@perl.org

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

Leopold Toetsch

unread,
Feb 25, 2005, 2:52:26 AM2/25/05
to Cory Spencer, perl6-i...@perl.org
Cory Spencer <cspe...@sprocket.org> 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

0 new messages