0

Long time ago I wrote following code to retrieve emails from mailbox:

pop3 := TNMPOP3.Create(Self);
try
  pop3.Host := FAppSettings.ServerName;
  pop3.Port := FAppSettings.ServerPort;
  pop3.UserID := FAppSettings.Login;
  pop3.Password := FAppSettings.Password;
  try
    pop3.Connect;
  except
    on E:Exception do AddError(E.Message);
  end;
  if not pop3.Connected then Exit;
  if pop3.MailCount > 0 then begin
    pop3.DeleteOnRead := False;
    pop3.AttachFilePath := GetTempDirectory;
    ProcessMsgs(pop3);
  end
  else begin
    TCommon.InfMsg('There are no messages in mailbox');
  end;
  pop3.Disconnect;
finally
  pop3.Free;
end;

Now, when mail service provider switched entirely to SSL this code fails obviously, but in a strange way:

pop3.Connect line causes an exception but with an empty text in E.Message making the problem unclear to end user.

Investigation of the problem in Delphi debugger reveals that the first time the right exception is generated:

Project .... raised exception class Exception with message 'Authentication failed'.

but then, when I press F8 (Step Over) again, execution point remains in the same line and another exception is generated:

Project .... raised exception class Exception with message ''.

and only this exception is catched by try-except.

Why?

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
Paul
  • 25,812
  • 38
  • 124
  • 247
  • Look at the code of `TNMPOP3` the reason should be in there – Sir Rufo Sep 21 '14 at 07:11
  • @Sir Rufo: I have no source code for `TNMPOP3` – Paul Sep 21 '14 at 07:20
  • 3
    After some googling around it seems that the FastNet components are a little bit buggy (friendly spoken) and you should think about using a different library. Because of Delphi 6 look at http://synapse.ararat.cz – Sir Rufo Sep 21 '14 at 07:23

1 Answers1

2

To answer your actual question of "why?", the sequence you describe means that TNMPOP3.Connect() is internally catching the original authentication exception and throwing a new exception without an error message. Whether that is a bug or intentional, there is no way to know without looking at the source code for TNMPOP3. Delphi did not ship with that source code, and NetMasters are no longer around so you can't ask them for it. TNMPOP3 does not support SSL anyway, so you will have to switch to another component/library to handle your POP3+SSL functionality moving forward.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Never knew that Delphi is able to dig into internal exceptions of a closed code without having sources =/ – Paul Sep 22 '14 at 12:04
  • It is not. What you described is happening while your app is running inside the IDE's debugger. When an exception is raised, the OS passes the exception to the debugger first, not the app. Delphi's debugger knows how to display exceptions derived from `SysUtils.Exception`, which is why you are able to see the class name and its message. Once the debugger is done with the exception, it is passed back to the app for further processing. While the app is processing it, another exception is being raised, which the debugger is displaying and then passing back to the app. – Remy Lebeau Sep 22 '14 at 16:00