Difference between revisions of "Raise"
From Lazarus wiki
Jump to navigationJump to searchm (Fixed syntax highlighting) |
|||
Line 1: | Line 1: | ||
{{Raise}} | {{Raise}} | ||
+ | |||
+ | |||
+ | Back to [[Reserved words]]. | ||
+ | |||
The [[Reserved word|reserved word]] <syntaxhighlight lang="pascal" enclose="none">raise</syntaxhighlight> is used to explicitly throw an [[Exceptions|exception]]. | The [[Reserved word|reserved word]] <syntaxhighlight lang="pascal" enclose="none">raise</syntaxhighlight> is used to explicitly throw an [[Exceptions|exception]]. | ||
The <syntaxhighlight lang="pascal" enclose="none">raise</syntaxhighlight> statement stops normal execution and transfers control to an exception handler. | The <syntaxhighlight lang="pascal" enclose="none">raise</syntaxhighlight> 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 == |
<syntaxhighlight lang="pascal"> | <syntaxhighlight lang="pascal"> | ||
Line 38: | Line 43: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | == See also == |
* [[Try| <syntaxhighlight lang="pascal" enclose="none">try</syntaxhighlight>]]..[[Finally|<syntaxhighlight lang="pascal" enclose="none">finally</syntaxhighlight>]] [[Block|block]]. | * [[Try| <syntaxhighlight lang="pascal" enclose="none">try</syntaxhighlight>]]..[[Finally|<syntaxhighlight lang="pascal" enclose="none">finally</syntaxhighlight>]] [[Block|block]]. |
Revision as of 01:35, 24 February 2020
│
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.