Difference between revisions of "Raise"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Raise}} The reserved word <syntaxhighlight lang="pascal" enclose="none">raise</syntaxhighlight> is used to explicitly throw an exception. T...")
 
Line 37: Line 37:
 
end.
 
end.
 
</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>]]..[[Except|<syntaxhighlight lang="pascal" enclose="none">except</syntaxhighlight>]] block.
 +
* [[On| <syntaxhighlight lang="pascal" enclose="none">on</syntaxhighlight>]]
 +
* [[runtime error|run-time error]]

Revision as of 08:51, 27 April 2019

Deutsch (de) English (en) suomi (fi)

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 briefly


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