Autor Beitrag
Magic2001
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


Delphi XE2
BeitragVerfasst: Mo 06.06.11 13:02 
Ich habe in meinem Code folgendes versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  try
    MachWas(Query1);
  except
    on E:Exception do
    begin
       showmessage(E.ClassName+':'+E.Message);
    end;
   Query1.Next; // nächster Datensatz
  end;


Aber anstatt der message bekomme ich nur die normale fehlermeldung wenn ich die .exe starte. Woran liegt das? Muss ich in den projektoptionen noch etwas einstellen?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19338
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 06.06.11 13:07 
Eigentlich nicht, aber ich hatte das glaube ich auch einmal. Ich habe das dann so gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
    try
    except
      on E: EDBEngineError do
        if (E.Errors[0].ErrorCode = $00002803)
          ...
      on E: Exception do
        raise;
    end;
Das ging.

In Except auf Next? Bist du sicher, dass das eine gute Idee ist? Wenn ohnehin schon etwas schiefgegangen ist? :gruebel:
Gerd Kayser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 632
Erhaltene Danke: 121

Win 7 32-bit
Delphi 2006/XE
BeitragVerfasst: Mo 06.06.11 13:22 
Müßte das try-except nicht eigentlich in der Funktion / Prozedur Machwas stehen? <grübel>
Magic2001 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


Delphi XE2
BeitragVerfasst: Mo 06.06.11 13:22 
Hier mein original Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
try
    polyline[i].lat :=  strtofloat(lat);
    polyline[i-5].lon :=  strtofloat(lon);
except
   on E:Exception do begin
     showmessage(E.ClassName+':'+E.Message);
     raise;
   end;


das i-5 löst einen Fehler aus: zugriffsverletzung bei .... Lesen von adresse...
Da ich mein Programm aber mit vernünftigen Fehlermeldungen ausstatten möchte (wo ich dann weis was den Fehler ausgelöst hat), dachte ich der oben gezeigte weg wäre der richtige.
Aber das funktioniert nicht.

Ich habe D2009
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 06.06.11 13:53 
Moin!

user profile iconMagic2001 hat folgendes geschrieben Zum zitierten Posting springen:
Aber das funktioniert nicht.
Was heißt "funktioniert nicht" denn genau? :nixweiss: Was passiert und was sollte passieren? :idea:

Probier das mal:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  try
    //...
  except
    ShowMessage(Exception(ExceptObject).ClassName+': '+Exception(ExceptObject).Message);
    raise;
  end;
cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mo 06.06.11 14:00 
user profile iconMagic2001 hat folgendes geschrieben Zum zitierten Posting springen:

das i-5 löst einen Fehler aus: zugriffsverletzung bei .... Lesen von adresse...


Kann es sein, dass du hier auf einen Index eines Arrays zugreifst, ohne vorher zu prüfen, ob du dich noch innerhalb der Grenzen des Arrays befindest? Das sieht hier ganz danach aus... (für alle i < 5 wie in deinem Beispiel führt dich a[i-5] auf eine Position ausserhalb der Arraygrenzen)

_________________
Delphi: XE - OS: Windows 7 Professional x64
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: Mo 06.06.11 14:17 
Richtig, anstatt an dem Fehler rum zu doktorn solltest du die Ursache dafür finden. Die Prüfung eines Index könnte so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  i: Integer; //Array-Index
  arr: array[-2..10of Integer; //Array

if (i >= Low(arr)) and (i <= High(arr)) then 
  arr[i] := StrToInt(EinText);


jetzt erfolgt der Zugriff auf das Array erst wenn der Index die richtige Größe hat. Im else-Block könnte man dann noch ne Fehlermeldung oder sowas ausgeben, wenn du das unbedingt willst.

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^