#!/usr/bin/perl use strict; use warnings; use Test::More tests => 2; { package TestCaller; use strict; use warnings; sub throw { my $self = bless {}, __PACKAGE__; my $i = 0; my @stack_trace; push @stack_trace, [ (caller($i))[0 .. 3] ] while caller(++$i); $self->{stack_trace} = \@stack_trace; die $self; } } eval { throw TestCaller }; isa_ok($@, 'TestCaller'); is_deeply($@->{stack_trace}, [[ 'main', 'test.pl', 24, '(eval)']], '... got the stack trace we expected'); 1;