AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Bubblen Exceptions nach oben durch einen try-finally-Block?
Thema durchsuchen
Ansicht
Themen-Optionen

Bubblen Exceptions nach oben durch einen try-finally-Block?

Ein Thema von DGL-luke · begonnen am 11. Feb 2007 · letzter Beitrag vom 11. Feb 2007
Antwort Antwort
Seite 1 von 3  1 23      
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#1

Bubblen Exceptions nach oben durch einen try-finally-Block?

  Alt 11. Feb 2007, 21:07
Hallo, folgende Struktur:

Delphi-Quellcode:
try
  with TSomeClass.Create do
    try
      SomeMethod;
      SomeMethodThatThrows; //wirft Exception!
    finally
      Free;
    end;
except
  on E:Exception do
    ShowmEssage(E.Message);
end;
Ich will eine Fehler bei der Erstellung der Klasse abfangen - innerhalb des try...finally-blocks interessieren mich keine Exceptions.

Klappt das oder kommt die Exception, die ich oben markiert hab, aus dem try...finally-block irgendwie raus?
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#2

Re: Bubblen Exception nach oben durch einen try-finally-Bloc

  Alt 11. Feb 2007, 21:12
Delphi-Quellcode:
with TSomeClass.Create do
try
  SomeMethod;
  SomeMethodThatThrows; //wirft Exception!
except
  on E:Exception do
    ShowmEssage(E.Message);
end;
Free;
So würd ich das machen.
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#3

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 21:14
Es dürfte kein Exception außerhalb des Blocks entstehen.
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 21:15
Negatori.

Ich will es abfangen, wenn die Klasse beim Erzeugen wirft. Im Konkreten geht es um einen Filestream.

@mkinzler: Ja, glaube das reicht mir.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#5

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 21:17
Das hättest du auch dazusagen können.
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#6

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 21:25
Hab ich.
Zitat von DGL-luke:
Ich will eine Fehler bei der Erstellung der Klasse abfangen
Und es ist mir egal, ob du sagst "du hast ja editiert". Ich hab da nur einen Buchstaben im titel geändert. (Kann das einer der Mods vielleicht bestätigen? ka, ob ihr da n versioning habt... )
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
PaulJr

Registriert seit: 9. Feb 2007
Ort: Stuttgart
66 Beiträge
 
#7

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 22:15
Hallo DGL-luke,

man könnte dies z.B. so machen:
Delphi-Quellcode:
var
  SomeClas : TSomeClas;
Begin

try
  SomeClas := TSomeClas.Create;
 If SomeClas <> NIL then
 with SomeClas do
    try
      SomeMethod;
      SomeMethodThatThrows; //wirft Exception!
    finally
      Free;
    end;
except
  on E:Exception do
    ShowmEssage(E.Message);
end;

end;
Gruß

PaulJr.
  Mit Zitat antworten Zitat
jbg

Registriert seit: 12. Jun 2002
3.481 Beiträge
 
Delphi 10.1 Berlin Professional
 
#8

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 22:25
Zitat von PaulJr:
SomeClas := TSomeClas.Create;
If SomeClas <> NIL then
Und in welchem Fall würde TSomeClas NIL zurückliefern? - In keinem. Somit ist die if-Anweisung sinnlos.
  Mit Zitat antworten Zitat
Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 22:26
Ich vermute mal, wenn der Konstruktor eine Exception wirft, bleibt der Pointer so, wie er vorher war. Das heißt, wenn man ihn vorher mit nil initialisiert, würde es gehen.
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#10

Re: Bubblen Exceptions nach oben durch einen try-finally-Blo

  Alt 11. Feb 2007, 22:33
Das funktioniert:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  fs: TFileStream;
begin
  try
  fs := TFileStream.Create('c:\test.txt', fmCreate);
  try

  finally
    FreeAndNil(fs);
  end;
  except
   on E: Exception do
     ShowMessage('foobar');
   end;
end;
Ich habe keine Schreibrechte auf c:\ und als Nachricht wird foobar aisgegeben.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz