eval { $msg->send_by_smtp; }; if ($@) { # handle error }