Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Exception in Funktion einbauen... (https://www.delphipraxis.net/28913-exception-funktion-einbauen.html)

Markus 1. Sep 2004 09:59


Exception in Funktion einbauen...
 
Hallo,

ich habe eine Funktion, hier mal ein Beispiel:

Delphi-Quellcode:
function test(text: string): boolean;
begin
if text='hallo' then result:=true
else begin
    result:=false;
    {hier soll jetzt eine Exception erzeugt werden (mit nem Bestimmen Text, z.B. "Text nicht richtig"}
end;
end;
Wie kann ich sowas nun realisieren?

mirage228 1. Sep 2004 10:01

Re: Exception in Funktion einbauen...
 
Delphi-Quellcode:
type
  EWrongText = class(Exception) end;

function test(text: string): boolean;
begin
  if text = 'hallo' then result:=true else
  begin
    result :=false;
    raise EWrongText.Create('Text nicht richtig');
  end;
end;
so z.B. ;)

mfG
mirage228


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:00 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