use Error qw(:try); use Error::File; # This is something you write use IO::File; # Stuff here ... my $fh = try { IO::File->new($filename) || throw Error::File -text => $!; } catch Error::File with { my $err = shift; die "Cannot open file\n"; };