my $s = eval { PHP::Session->new() }; if ($s) { # I CAN HAZ SESSION } else { # there was an error }