105 lines
2.5 KiB
HTML
105 lines
2.5 KiB
HTML
<html>
|
|
<head>
|
|
<link rel=stylesheet type="text/css" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<H2>
|
|
Pascal samples. Exception handling.
|
|
</H2>
|
|
<hr>
|
|
|
|
<H4>
|
|
Example 1
|
|
</H4>
|
|
<blockquote>
|
|
<pre>
|
|
<font color="blue"><b>uses</b></font>
|
|
SysUtils;
|
|
|
|
<font color="blue"><b>procedure</b></font> ErrorProc;
|
|
<font color="blue"><b>var</b></font>
|
|
I: Integer;
|
|
<font color="blue"><b>begin</b></font>
|
|
I := 0;
|
|
I := I div I;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TestExcept;
|
|
<font color="blue"><b>var</b></font>
|
|
S: <font color="blue"><b>String</b></font>;
|
|
I: Integer;
|
|
<font color="blue"><b>begin</b></font>
|
|
S := <font color="Red">'abc'</font>;
|
|
<font color="blue"><b>try</b></font>
|
|
ErrorProc;
|
|
<font color="blue"><b>except</b></font>
|
|
<font color="blue"><b>on</b></font> E:EDivByZero <font color="blue"><b>do</b></font>
|
|
<font color="blue"><b>begin</b></font>
|
|
writeln(S);
|
|
S := E.Message;
|
|
writeln(S);
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>else</b></font>
|
|
<font color="blue"><b>begin</b></font>
|
|
writeln(456);
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>begin</b></font>
|
|
TestExcept;
|
|
writeln(<font color="Red">'ok'</font>);
|
|
<font color="blue"><b>end</b></font>.
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<H4>
|
|
Example 2
|
|
</H4>
|
|
<blockquote>
|
|
<pre>
|
|
<font color="blue"><b>uses</b></font>
|
|
SysUtils;
|
|
|
|
<font color="blue"><b>procedure</b></font> ErrorProc;
|
|
<font color="blue"><b>var</b></font>
|
|
I: Integer;
|
|
<font color="blue"><b>begin</b></font>
|
|
I := 0;
|
|
I := I div I;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TestFinally;
|
|
<font color="blue"><b>var</b></font>
|
|
S: <font color="blue"><b>String</b></font>;
|
|
I: Integer;
|
|
<font color="blue"><b>begin</b></font>
|
|
S := <font color="Red">'abc'</font>;
|
|
<font color="blue"><b>try</b></font>
|
|
ErrorProc;
|
|
<font color="blue"><b>finally</b></font>
|
|
writeln(S);
|
|
<font color="blue"><b>end</b></font>;
|
|
writeln(<font color="Red">'not executed'</font>);
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>begin</b></font>
|
|
<font color="blue"><b>try</b></font>
|
|
TestFinally;
|
|
<font color="blue"><b>except</b></font>
|
|
writeln(<font color="Red">'ok'</font>);
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>.
|
|
</pre>
|
|
</blockquote>
|
|
|
|
|
|
<p>
|
|
<HR>
|
|
<font size = 1 color ="gray">
|
|
Copyright © 2006-2009
|
|
VIRT Laboratory. All rights reserved.
|
|
</font>
|
|
</body>
|
|
</html>
|