Difference between revisions of "Raise"

From Free Pascal wiki
Jump to navigationJump to search
m (Fixed syntax highlighting)
Line 5: Line 5:
  
  
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" inline>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" 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" enclose="none">try</syntaxhighlight>]]..[[Finally|<syntaxhighlight lang="pascal" enclose="none">finally</syntaxhighlight>]] [[Block|block]].
+
* [[Try| <syntaxhighlight lang="pascal" inline>try</syntaxhighlight>]]..[[Finally|<syntaxhighlight lang="pascal" inline>finally</syntaxhighlight>]] [[Block|block]].
* [[Try| <syntaxhighlight lang="pascal" enclose="none">try</syntaxhighlight>]]..[[Except|<syntaxhighlight lang="pascal" enclose="none">except</syntaxhighlight>]] block.
+
* [[Try| <syntaxhighlight lang="pascal" inline>try</syntaxhighlight>]]..[[Except|<syntaxhighlight lang="pascal" inline>except</syntaxhighlight>]] block.
* [[On| <syntaxhighlight lang="pascal" enclose="none">on</syntaxhighlight>]]
+
* [[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:

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.

See also