Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How to capture the failure reason of Email::Sender?

by vitoco (Hermit)
on Oct 02, 2018 at 05:22 UTC ( [id://1223383]=perlquestion: print w/replies, xml ) Need Help??

vitoco has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I'm trying to log the email sending result using Email::Sender, both OK and failure. In the doc, it says that when the message was sent, the result will be an Email::Sender::Success object that it is only a "true" value, but I found that it has a "message" property and I use it to write in the log.

The problems start when there is an error. The doc says that it will throw an object of the class Email::Sender::Failure with a "message" attribute describing the error, but it also dies!!! To avoid the unexpected finish, the module includes a method called "try_to_send", but on error it only returns "false" and no messages. Alternatively I could use Try::Tiny by myself, but I couldn't retrieve a "message" attribute in this case. Also, I couldn't find an example on how to catch the failure object correctly...

Any hint? Thanks in advance!

  • Comment on How to capture the failure reason of Email::Sender?

Replies are listed 'Best First'.
Re: How to capture the failure reason of Email::Sender?
by choroba (Cardinal) on Oct 02, 2018 at 07:58 UTC
    The thing Try::Tiny catches is the thrown error object, so inspect it.
    #!/usr/bin/perl use warnings; use strict; use Try::Tiny; sub My::Error::message { shift->{message} } try { die bless { message => 'Not enough resources' }, 'My::Error' } catch { my $error = $_; warn $error->message; }
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      So $_ has the captured object... Now I see it! :-)

      Thank you!!!!!

Re: How to capture the failure reason of Email::Sender?
by Jenda (Abbot) on Oct 02, 2018 at 14:56 UTC

    If it throws an exception and you don't catch it, then the program dies. In pure Perl you throw using the die() builtin and catch using the eval BLOCK builtin.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1223383]
Approved by haukex
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found