Autor Beitrag
Jacdelad
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Mo 31.07.06 20:45 
Hallo Leute!

Ich möchte gern Fehler (also Exceptions) abfangen. Hab mir jetzt mal alles zu ErrorProc und so weiter durchgelesen, komme aber nicht so richtig dahinter. Kann mir jemand vielleicht ein Beispiel posten??

Jac

_________________
Es gibt 10 Arten von Menschen: Die einen, die Binärcode verstehen und die, die es nicht tun.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 31.07.06 21:54 
So zum Beispiel:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
type
  EPassWord = class(Exception)
    public
      constructor Create(const PW: String); reintroduce;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

constructor EPassWord.Create(const PW: String);
resourcestring
  rsBadPW = 'Das Passwort %s ist falsch';
begin
  inherited Create(Format(rsBadPW, [PW]));
end;

procedure CheckPW(const PW: String);
begin
  if PW <> 'Hello' then
    raise EPassWord.Create(PW);
end;

procedure TForm1.Button1Click(Sender: TObject);
resourcestring
  rsWrongPW = 'Mist, falsch';
begin
  try
    CheckPW(Edit1.Text);
  except
    on E: EPassWord do ShowMessage(rsWrongPW);
    on E: Exception do ShowMessage(E.Message);
  end;
end;
Jacdelad Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Di 01.08.06 19:14 
Hm, das kenne ich schon, meine Sache ist aber, dass ich nicht einen Try-Except-Block aufbauen will, sondern jeden Fehler abfangen will, der entsteht (beispielsweise weil mein Programm sehr umfangreich ist und andauernd abstürzt). Ich will also jede Exception abfangen die auftritt.

Jac

_________________
Es gibt 10 Arten von Menschen: Die einen, die Binärcode verstehen und die, die es nicht tun.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Di 01.08.06 19:48 
Stichwort TApplicationEvents.OnException
und: Verweis auf Delphi-Hilfe, Suche, tutorials, etc.

_________________
Programmers never die, they just GOSUB without RETURN
Jacdelad Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Mi 02.08.06 19:45 
Danke, ich schaus mir an!

Jac

_________________
Es gibt 10 Arten von Menschen: Die einen, die Binärcode verstehen und die, die es nicht tun.
Jacdelad Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Mi 02.08.06 20:42 
Hallo!

Also ich komme mal wieder nicht damit klar (ich sattel von XProfan um, das ist noch weitgehend prozedural, obwohl man auch objektorientiert proggen kann, jedenfalls komme ich mit den ganzen Prozeduren, Methoden und Eigenschaften etc. nicht klar). Kann sich vielleicht jemand ein Minimalbeispiel aus dem Kreuz leiern?

Jac

_________________
Es gibt 10 Arten von Menschen: Die einen, die Binärcode verstehen und die, die es nicht tun.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 02.08.06 21:19 
1. Eintrag bei Google bei Suche nach Suche bei Google APPLICATION.ONEXCEPTION:
www.clevercomponents...05/sendbugreport.asp
ausblenden gekürzt
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TMyAppForm.DoHandleException(Sender: TObject; E: Exception); 
var 
   IsContinuable: Boolean; 
   Msg: TStrings; 
begin 
   IsContinuable := not (E is EAccessViolation); 

   Msg := TStringList.Create(); 
   try 
      if IsContinuable then 
         Msg.Add('The program raised continuable exception and still can continue operating.'
      else 
         Msg.Add('The program raised non-continuable exception and will be closed.'); 

      Msg.Add(E.Message); 
   finally 
      Msg.Free(); 
   end

   if not IsContinuable then 
      Halt; 
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 03.08.06 11:35 
user profile iconJacdelad hat folgendes geschrieben:
dass ich nicht einen Try-Except-Block aufbauen will, sondern jeden Fehler abfangen will, der entsteht (beispielsweise weil mein Programm sehr umfangreich ist und andauernd abstürzt). Ich will also jede Exception abfangen die auftritt.

Da würde ich an deiner Stelle mal die Fehler suchen. Das, was du vorhast, ist nicht sehr empfehlenswert.
Jacdelad Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Fr 04.08.06 17:21 
Ja, ich weiß, ich hab in dem Programm auch keine Fehler drin (soweit ich weiß), aber das Windows auch manchmal macht, was es will, wollte ich solche Sachen ahlt vorsichtshalber abfangen!

Jac

_________________
Es gibt 10 Arten von Menschen: Die einen, die Binärcode verstehen und die, die es nicht tun.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 04.08.06 22:25 
Windows macht nicht was es will, aber der, der vor dem PC sitzt.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)