Difference between revisions of "Raise"
From Free Pascal wiki
Jump to navigationJump to searchm (Fixed syntax highlighting) |
|||
Line 5: | Line 5: | ||
− | The [[Reserved word|reserved word]] <syntaxhighlight lang="pascal" | + | The [[Reserved word|reserved word]] <syntaxhighlight lang="pascal" inline>raise</syntaxhighlight> is used to explicitly throw an [[Exceptions|exception]]. |
− | The <syntaxhighlight lang="pascal" | + | The <syntaxhighlight lang="pascal" inline>raise</syntaxhighlight> statement stops normal execution and transfers control to an exception handler. |
== Summary == | == Summary == | ||
Line 45: | Line 45: | ||
== See also == | == See also == | ||
− | * [[Try| <syntaxhighlight lang="pascal" | + | * [[Try| <syntaxhighlight lang="pascal" inline>try</syntaxhighlight>]]..[[Finally|<syntaxhighlight lang="pascal" inline>finally</syntaxhighlight>]] [[Block|block]]. |
− | * [[Try| <syntaxhighlight lang="pascal" | + | * [[Try| <syntaxhighlight lang="pascal" inline>try</syntaxhighlight>]]..[[Except|<syntaxhighlight lang="pascal" inline>except</syntaxhighlight>]] block. |
− | * [[On| <syntaxhighlight lang="pascal" | + | * [[On| <syntaxhighlight lang="pascal" inline>on</syntaxhighlight>]] |
* [[runtime error|run-time error]] | * [[runtime error|run-time error]] |
Revision as of 17:21, 6 August 2022
│
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.