my %XMap = ( 'MyException::Class1'=>1, 'MyException::Class2'=>2, ... ); sub errorcode { my $ex = shift; my $type = ref $ex; return $XMap{$type} if exists $XMap{$type} return 3; # default }