Raise
From Lazarus wiki
Revision as of 16:21, 6 August 2022 by Kai Burghardt (talk | contribs) (resolve Category: Pages using deprecated enclose attributes)
│
Deutsch (de) │
English (en) │
suomi (fi) │
Back to Reserved words.
The reserved word raise
is used to explicitly throw an exception.
The raise
statement stops normal execution and transfers control to an exception handler.
Summary
The reserved word raise:
- belongs to object-oriented programming;
- causes an exception.
Example
program Example1;
uses sysutils;
function titleread(a_title:string):string;
var
answer:string;
begin
writeln ( a_title);
readln(answer);
if answer = '' then raise Exception.Create('Variable has no value');
result := answer;
end;
var
firstname,lastname:string;
begin
firstname := titleread( 'Write your first name:');
lastname := titleread( 'Write your last name:');
writeln ('your name is ', firstname, ' ', lastname);
readln;
end.