Difference between revisions of "Try"
From Free Pascal wiki
Jump to navigationJump to search (Created page with "{{Try}} The reserved word <syntaxhighlight lang="pascal" enclose="none">try</syntaxhighlight> is part of either a <syntaxhighlight lang="pascal" enclose="no...") |
|||
Line 31: | Line 31: | ||
== See also == | == See also == | ||
* [[Raise]] | * [[Raise]] | ||
+ | * [[On]] |
Revision as of 19:12, 3 April 2019
│
Deutsch (de) │
English (en) │
español (es) │
suomi (fi) │
русский (ru) │
The reserved word try
is part of either a try
..finally
block or a
try
..except
block.
If an exception occurs while executing the code between try
and
finally
, execution resumes at finally
. If no exception occurs, the code between finally
and
end
will be executed also.
try
// code that might generate an exception
finally
// will always be executed as last statements
end;
Whenever an exception occurs, the code between except
and end
will be executed.
try
// code that might generate an exception
except
// will only be executed in case of an exception
on E: EDatabaseError do
ShowMessage( 'Database error: '+ E.ClassName + #13#10 + E.Message );
on E: Exception do
ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );
end;