3
TestObject - An implementation of TestInterface
7
This module attempts to provide an implementation of TestInterface and
8
is used for illustrating exception throwing using Graham Barr's
13
Steve Chervitz E<lt>sac@bioperl.orgE<gt>
27
# Define a special type of error "Bio::TestException" as a subclass of Error.
29
# 1. The ISA declaration effectively defines our new Exception object.
30
# 2. This declaration doesn't have to be located in the Bio directory.
31
# 3. We don't have to use Bio::Root::Exception in this module.
32
# 4. If Error.pm isn't available this statement doesn't matter.
33
@Bio::TestException::ISA = qw( Bio::Root::Exception );
35
@ISA = qw( Bio::Root::Root TestInterface );
38
# Note that we're not implementing foo(), so calling it
39
# will result in a Bio::Root::NotImplemented exception.
42
my ($self, $data) = @_;
43
print "Setting test data ($data)\n" if $data;
44
$self->{'data'} = $data if $data;
46
return $self->{'data'}
53
print "\nExecuting method bar() in TestObject\n";
54
print "Throwing a Bio::TestException\n";
56
my $message = "A Test error";
58
# Bio::Root::Root::throw() will make use of Error.pm if present.
59
# The type of Error is specified with a -class parameter.
60
# If -class is not supplied, a Bio::Root::Exception is throw.
61
# In this case, the argument can consist of a simple string.
63
$self->throw( -class => 'Bio::TestException',
66
print "Code within bar() below the throw that shouldn't be executed.\n";