use strict; use warnings; use GD; $SIG{__WARN__} = sub { print "Caught warning: ".$_[0] }; my $image; eval { ($image = GD::Image->new("test.jpg")) or warn "Error: ".$!; }; if ($@) { print "Caught ".$@; } if (defined($image)) { print "Image is defined: ".$image."\n"; }