Test::Exception


Test::Exception.


examples/test-warn/t/test_exception.t
use strict;
use warnings;

use Test::More;
use Test::Exception;

use MyTools qw(fibo);

is fibo(6), 8, 'fibo(6)';

throws_ok { fibo() } qr/Need to get a parameter/, 'missing parameter';
throws_ok { fibo('name') } qr/Need to get a number/, 'not a number';

done_testing;

1..2
ok 1 - div by 2
ok 2 - div by zero


throws_ok { $foo->method } 'Error::Simple', 'simple error thrown';

Where Error::Simple is the class of the exception that have been thrown. e.g. by Exception::Class.