#!/usr/bin/perl use 5.010; use strict; use warnings; use TryCatch; try { Exception::Test->throw('Error!') if eq "test\n"; Exception->throw('Error!'); } # try catch (Exception::Test $e) { say "Exception::Test: ". $$e; } # catch catch ($e) { say "Other: ". $$e; } # catch package Exception; sub throw { my( $class, $error ) = @_; die bless \$error, $class; } # throw package Exception::Test; #edit: use parent -norequire, 'Exception';