File: Exception.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (71 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*-Perl-*- Test Harness script for Bioperl
# $Id: Exception.t 15283 2009-01-02 22:16:55Z cjfields $

use strict;

BEGIN {
	eval {require Error;};
	
	use lib '.';
	use Bio::Root::Test;
	
	test_begin(-tests => 8,
			   -requires_module => 'Error');
	
	use lib './examples/root/lib';
	use_ok('TestObject');
}

use Error qw(:try);
$Error::Debug = test_debug(); 

# Set up a tester object.
ok my $test = TestObject->new(-verbose => test_debug());

is $test->data('Eeny meeny miney moe.'), 'Eeny meeny miney moe.';

# This demonstrates what will happen if a method defined in an
# interface that is not implemented in the implementating object.

eval { 
    try {
		$test->foo();
    }
    catch Bio::Root::NotImplemented with {
		my $err = shift;
		is ref $err, 'Bio::Root::NotImplemented';
    };
};

# TestObject::bar() deliberately throws a Bio::TestException, 
# which is defined in TestObject.pm
try {
    $test->bar;
}
catch Bio::TestException with {
    my $err = shift;
    is ref $err, 'Bio::TestException';
};


# Use the non-object-oriented syntax to throw a generic Bio::Root::Exception.
try {
    throw Bio::Root::Exception( "A generic error", 42 );
}
catch Bio::Root::Exception with {
    my $err = shift;
    is ref $err, 'Bio::Root::Exception';
    is $err->value, 42;
};

# Try to call a subroutine that doesn't exist. But because it occurs
# within a try block, the Error module will create a Error::Simple to
# capture it. Handy eh?

try {
	$test->foobar();
}
otherwise {
	my $err = shift;
	is ref $err, 'Error::Simple';
};