Autor Beitrag
eraser_seb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Fr 27.08.10 08:42 
Hallo ich habe ein problem mit Exceptions.
Ich wollte eine Exception auslösen, aber wenn ich die Exception auslöse kommt ein Fehler. "Zugriffsverletzung ..."
Quellcode Beispiel
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure pruefezahl(zahl : integer);
begin
if zahl = 0 then 
   raise Exception.create('zahl ist null'); //<-- zugriffsverletzung
end;

procedure test;
begin
try
   pruefezahl(0);
except
  on e:exception on showmessage(e.message);
end;
end;


Wenn die Exception ausgelöst wird kommt die zugriffsverletzung.

Bitte weiss nicht warum die Zugriffsverletzung kommt.


Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am Fr 27.08.2010 um 12:47
Stundenplan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 32

Win 7
Delphi 7 Pers., C# (VS 2010 Express)
BeitragVerfasst: Fr 27.08.10 09:02 
Also bei mir kommt da keine Zugriffsverletzung, ich sehe da nur die "Zahl ist null"-Meldung!:nixweiss: Außerdem heißt das on e:exception do showmessage(e.message);.

Viele Grüße,
Stundenplan.
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Fr 27.08.10 09:29 
In dem Fall reicht ein raise im except Block.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 27.08.10 10:37 
Hey,

läuft das ganze im Debugger? Der zeigt dir alle Exceptions an, auch wenn sie danach abgefangen werden. Einfach nach der Exception nochma F9 drücken oder die Exe probieren.
@thepaine91: Ich glaube das soll nur so zum Test sain ;)

Mfg Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Fr 27.08.10 11:38 
@Bergmann bei einer zugriffsverletzung bezweifel ich das er mit F9 ^^ weiter kommt ;)
Und ja kann gut sein wollte es nur mal anmerken. =)
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 27.08.10 13:03 
Wieso nich? Bei folgendem Code sagt der Debugger, dass die Exception aufgetreten ist (und pausiert den Programmablauf). Dann drück ich F9 (also lass das Programm weiter laufen). Er arbeitet den Except-Block ab und gibt mir die Meldung aus...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  try
    raise Exception.Create('Blaa');
  except
    on e: Exception do ShowMessage(e.Message);
  end;


€: sry, Zugriffsverletzung mit Exception verwechsel :oops:

MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
eraser_seb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Fr 27.08.10 13:25 
Ich danke euch allen für eure antwortee. Die Lösung ist der Hammer. Delphi neustart. arbeite noch mit Delphi %(heul) aber jetzt gehts.

Danke euch nochmal