fix subversion tags
[bioperl-live.git] / t / Exception.t
blobedbebf63b46c62d923c9e27b26f03adeb61cd6eb
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7         eval {require Error;};
8         
9         use lib 't/lib';
10         use BioperlTest;
11         
12         test_begin(-tests => 8);
13         
14         use lib './examples/root/lib';
15         use_ok('TestObject');
18 use Error qw(:try);
19 $Error::Debug = test_debug(); 
21 # Set up a tester object.
22 ok my $test = TestObject->new(-verbose => test_debug());
24 is $test->data('Eeny meeny miney moe.'), 'Eeny meeny miney moe.';
26 # This demonstrates what will happen if a method defined in an
27 # interface that is not implemented in the implementating object.
29 eval { 
30     try {
31                 $test->foo();
32     }
33     catch Bio::Root::NotImplemented with {
34                 my $err = shift;
35                 is ref $err, 'Bio::Root::NotImplemented';
36     };
39 # TestObject::bar() deliberately throws a Bio::TestException, 
40 # which is defined in TestObject.pm
41 try {
42     $test->bar;
44 catch Bio::TestException with {
45     my $err = shift;
46     is ref $err, 'Bio::TestException';
50 # Use the non-object-oriented syntax to throw a generic Bio::Root::Exception.
51 try {
52     throw Bio::Root::Exception( "A generic error", 42 );
54 catch Bio::Root::Exception with {
55     my $err = shift;
56     is ref $err, 'Bio::Root::Exception';
57     is $err->value, 42;
60 # Try to call a subroutine that doesn't exist. But because it occurs
61 # within a try block, the Error module will create a Error::Simple to
62 # capture it. Handy eh?
64 try {
65         $test->foobar();
67 otherwise {
68         my $err = shift;
69         is ref $err, 'Error::Simple';
70 };