Autor Beitrag
Peter2002
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103

Win XP, Win 7
Delphi 2007 / XE3
BeitragVerfasst: Do 29.08.02 17:23 
Hallo,
bei der FastNet-Kompo NMSMTP gibt Ereignise, wie OnAuthenticationFaild, OnConnectionFaild, OnInvaildHost ..., die sich wunderbar eignen, um entsprchende Fehlermeldungen auszugeben.
Bei der Indy-Kompo idSMTP gibts keine solchen Ereignisse.
Wie kann ich hier auf solche Fehler reagieren?
Arakis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: Do 29.08.02 17:34 
Willst du sie abfangen, behandeln oder protokollieren? Zum Protokollieren kannst du gut folgendes nutzen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.func_error(Sender: TObject; E: Exception);
begin
  self.Memo1.Lines.Add(e.Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnException := func_error;
end;


Bis dann,
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!
Peter2002 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103

Win XP, Win 7
Delphi 2007 / XE3
BeitragVerfasst: Do 29.08.02 20:06 
Das ist nicht so ganz, das was ich suche.

Eigentlich wollte ich nur eine Meldung ausgeben, wenn beispielsweise die UserID falsch ist.

Früher hatte ich das immer so gelöst:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.NMSMTP1AuthenticationFailed(var Handled: Boolean);
begin
  Auth_failed := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ...
  Auth_failed := false;
  try
    NMSMTP1.Connect;
    NMSMTP1.SendMail;
  except
    if Auth_failed then MessageDlg ('UserID od. Kennwort fehlerhaft', mtError, [mbOK],0);
   ...
  end;
 ...
Arakis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: Do 29.08.02 20:34 
Mach mal folgendes: Geh in der IDE auf Tools/Debugger Optionen/Sprach Exception und trage dort per Hinzufügen den Namen der Indy-Exception ein, z.B. EIdProtocolReplyError
Damit ist taucht keine Exception mehr auf dem Bildschirm auf. Um diese dennoch abzufangen, nutzt du folgenden Code(Beispiel für FTP):
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
try
  IdFTP.Connect;
except
  on E:Exception Do
  Begin
    showmessage(E.Message);
    IdFTP.Abort;
    exit;
  End;
End;

Bis dann
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!
Peter2002 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103

Win XP, Win 7
Delphi 2007 / XE3
BeitragVerfasst: Fr 30.08.02 08:06 
wir kommen der sache schon näher.
Aber wie kann ich jetzt meine eigenen Meldungen ausgeben. Ich kann da doch nicht tausend ifs machen, oder?
...
if E.Message='blabla' then Meine Meldung
...
Peter2002 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103

Win XP, Win 7
Delphi 2007 / XE3
BeitragVerfasst: Mo 02.09.02 16:07 
Gibt es keine Möglichkeit eigene Fehlermeldungen auszugeben?
Haben die Zahlen, dich in E.Message mit dabei stehen eine Bedeutung?
Arakis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: Mo 02.09.02 16:14 
Hi,
eine eigene Exception kannst du so hervorrufen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var
  e: Exception;
begin
  e := Exception.Create('Meine eigene Exception');
  application.ShowException(e);
  //oder
  raise e;
end;

Bis dann
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!
Peter2002 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103

Win XP, Win 7
Delphi 2007 / XE3
BeitragVerfasst: Mo 02.09.02 16:38 
ich will keine eigenen exceptions hervorrufen, sondern diese abfangen.
wir waren in vorigen Postings glaub schon ganz nah dran.

Wenn ich idSMTP.connect aufrufe und beispielsweise die UserID falsch ist, dann wird eine Exception ausgelöst. Diese möchte ich abfangen.
Mir gefällt nur nicht so gut, dass ich das dann in etwa so machen müsste

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
...
try
  SMTP.connect;
except
  on E: Exception do
    if E.Message = '535 authorization failed (#5.7.0)' then ShowMessage ('UserID oder Kennwort falsch');
end;
...


bekomme ich eigentlich immer die selbe Message? Egal über wen ich versuche emails zu senden. (Yahoo!, GMX ...)