Search code examples
smalltalkpharo

Error handling For SMTPClient


[SMTPClient
    deliverMailFrom: sender
    to: recipient
    text: message
    usingServer: 'mail.google.com']
        on: Error
        do:["Transcript show:'Sumthing went wrong'"].

If SMTPClient raises an Error saying TelnetProtocolError or ConnectionTimedOut. What's the right way to just make the Transcript display my message?


Solution

  • You can always use a parameter in the #do: block to get information about the exception:

    [SMTPClient
        deliverMailFrom: sender
        to: recipient
        text: message
        usingServer: 'mail.google.com']
            on: Error
            do:[:e | Transcript show: e].
    

    The :e parameter in the #do: block is an instance of the error that has been raised.