Re: Convert Connect & Send Delphi Exceptions to meaningful text

Giganews Newsgroups
Subject: Re: Convert Connect & Send Delphi Exceptions to meaningful text
Posted by:  Remy Lebeau \(TeamB\) (no.spam@no.spam.com)
Date: Tue, 17 Jun 2008

"Tom" <no…@none.com> wrote in message news:E66A79729457E340no…@none.com...

> With Indy 9 and Delphi, how can I convert an exception to
> a meaningful error message rather than just a numeric code?

Use the Exception's Message property like any other exception.  Indy already
performs the translation for you.

> I have not idea if the code below is the right approach.

No, not even close.  Try this instead:

    try
        idSMTP.Connect(1000);
        idSMTP.Send(MailMessage);
    except
        on E: EIdSocketError do
        begin
            // for WinSock errors
            ErrorResult := E.LastError;
            Errm := E.Message;
        end;
        on E: EIdReplyRFCError do
        begin
            // for server error codes
            ErrorResult := E.ErrorCode;
            Errm := E.Message;
        end;
        on E: Exception do
        begin
            // for all other general exceptions
            Errm := E.Message;
        end;
        ...
    end;

Gambit

Replies

In response to

Convert Connect & Send Delphi Exceptions to meaningful text posted by Tom on Fri, 13 Jun 2008