3 <title>KOL Help: Exception class (main frame)
</title>
7 <body bgcolor=
"#FFFFEF" text=
"#000000" link=
"#008080" vlink=
"#008000" alink=
"#808000">
8 <p><font face=
"Courier" color=
"#800080"><b>Exception( unit
<a href=err_pas.htm
>err.pas
</a> )
9 <font face=
"Wingdings">ï
</font> TObject
12 Exception = class( TObject )
14 Exception class. In
<a href=kol_pas.htm
>KOL
</a>, there is a single exception class is used.
15 Instead of inheriting new exception classes from this ancestor, an
16 instance of the same Exception class should be used. The difference
17 is only in
<a href=#code
target=
"main">Code
</a> property, which contains a kind of exception.
18 <h3 align=
"center"><font color=
"#FF8080">Exception properties
</font></h3>
19 <a name=
"message"></a>
21 <font face=
"Courier" color=
"#800080"><b>property
</b> <font color=
"#808000"><b>Message
</b></font>:
<b>string
</b>;
</font>
22 <font face=
"Webdings" size=
7>Ñ</font>
24 Text string, containing descriptive message about the exception.
28 <font face=
"Courier" color=
"#800080"><b>property
</b> <font color=
"#808000"><b>Code
</b></font>:
<a href=err_pas.htm#terror
target=
"_top">TError
</a>;
</font>
29 <font face=
"Webdings" size=
7>Ñ</font>
31 Main exception code. This property can be used to determine, which exception
34 <a name=
"errorcode"></a>
36 <font face=
"Courier" color=
"#800080"><b>property
</b> <font color=
"#808000"><b>ErrorCode
</b></font>:
<b>DWORD
</b>;
</font>
38 This code is to detailize error. For
<a href=#code
target=
"main">Code
</a> = e_InOut, ErrorCode contains
39 more detail description of input/output error. For e_Custom, You can
40 assign it to any value You want.
42 <a name=
"exceptionrecord"></a>
44 <font face=
"Courier" color=
"#800080"><b>property
</b> <font color=
"#808000"><b>ExceptionRecord
</b></font>: PExceptionRecord;
</font>
45 <font face=
"Webdings" size=
7>Ñ</font>
47 This property is only for e_External exception.
51 <font face=
"Courier" color=
"#800080"><b>property
</b> <font color=
"#808000"><b>Data
</b></font>:
<b>Pointer
</b>;
</font>
53 Custom defined pointer. Use it in your custom exceptions.
55 <h3 align=
"center"><font color=
"#FF8080">Exception methods
</font></h3>
58 <font face=
"Courier" color=
"#800080"><b>constructor
</b> <font color=
"#808000"><b>Create
</b></font>( ACode:
<a href=err_pas.htm#terror
target=
"_top">TError
</a>;
<b>const
</b> Msg:
<b>string
</b> );
</font>
60 Use this constructor to raise exception, which does not require of
63 <a name=
"createfmt"></a>
65 <font face=
"Courier" color=
"#800080"><b>constructor
</b> <font color=
"#808000"><b>CreateFmt
</b></font>( ACode:
<a href=err_pas.htm#terror
target=
"_top">TError
</a>;
<b>const
</b> Msg:
<b>string
</b>;
<b>const
</b> Args:
<b>array
</b> <b>of
</b> <b>const
</b> );
</font>
67 Use this constructor to raise an exception with formatted
<a href=#message
target=
"main">Message
</a> string.
68 Take into attention, that
<a href=kol_pas.htm#format
>Format
</a> procedure defined in
<a href=kol_pas.htm
>KOL
</a>, uses API wvsprintf
69 function, which can understand a restricted set of format specifications.
71 <a name=
"createcustom"></a>
73 <font face=
"Courier" color=
"#800080"><b>constructor
</b> <font color=
"#808000"><b>CreateCustom
</b></font>( AError:
<b>DWORD
</b>;
<b>const
</b> Msg:
<b>String
</b> );
</font>
75 Use this constructor to create e_Custom exception and to assign AError to
76 its
<a href=#errorcode
target=
"main">ErrorCode
</a> property.
78 <a name=
"createcustomfmt"></a>
80 <font face=
"Courier" color=
"#800080"><b>constructor
</b> <font color=
"#808000"><b>CreateCustomFmt
</b></font>( AError:
<b>DWORD
</b>;
<b>const
</b> Msg:
<b>String
</b>;
<b>const
</b> Args:
<b>array
</b> <b>of
</b> <b>const
</b> );
</font>
82 Use this constructor to create e_Custom exception with formatted message
83 string and to assign AError to its
<a href=#errorcode
target=
"main">ErrorCode
</a> property.
85 <a name=
"createresfmt"></a>
87 <font face=
"Courier" color=
"#800080"><b>constructor
</b> <font color=
"#808000"><b>CreateResFmt
</b></font>( ACode:
<a href=err_pas.htm#terror
target=
"_top">TError
</a>; Ident:
<b>Integer
</b>;
<b>const
</b> Args:
<b>array
</b> <b>of
</b> <b>const
</b> );
</font>
90 <a name=
"destroy"></a>
92 <font face=
"Courier" color=
"#800080"><b>destructor
</b> <font color=
"#808000"><b>Destroy
</b></font>;
<b>override
</b>;
</font>
96 <h3 align=
"center"><font color=
"#FF8080">Exception events
</font></h3>
97 <a name=
"ondestroy"></a>
99 <font face=
"Courier" color=
"#800080"><b>property
</b> <font color=
"#808000"><b>OnDestroy
</b></font>: TDestroyException;
</font>
101 This event is to allow to do something when custom Exception is
104 <a name=tasks
></a><h3 align=
"center"><font color=
"#FF8080">Exception tasks
</font></h3>
105 With err unit, it is possible to use all capabilities of Delphi exception
106 handling almost in the same way as usual. The difference only in that the
107 single exception class should be used. To determine which exception occure,
108 use property
<a href=#code
target=
"main">Code
</a>. So, code to handle exception can be written like follow:
109 <p align=left
><font face=
"Courier" color=
"008080"><b><pre>
112 except on E: Exception
<font color=
"800000"><b>do
</b></font>
113 <font color=
"800000"><b>case
</b></font> E.
<a href=
"exception.htm#code"><font color=
"008080">Code
</font></a> <font color=
"800000"><b>of
</b></font>
114 e_DivBy0: HandleDivideByZero;
115 e_Overflow: HandleOverflow;
117 <font color=
"800000"><b>end
</b></font>;
118 <font color=
"800000"><b>end
</b></font>;
119 </pre></b></font></p>
120 To raise an error, create an instance of Exception class object, but
121 pass a
<a href=#code
target=
"main">Code
</a> to its constructor:
122 <p align=left
><font face=
"Courier" color=
"008080"><b><pre>
123 <font color=
"800000"><b>var
</b></font> E: Exception;
125 E := Exception.
<a href=
"exception.htm#create"><font color=
"008080">Create
</font></a>( e_Custom,
<font color=
"A08020">'My custom exception'
</font> );
126 E.
<a href=
"exception.htm#errorcode"><font color=
"008080">ErrorCode
</font></a> := MY_MAGIC_CODE_FOR_CUSTOM_EXCEPTION;
128 </pre></b></font></p>
130 <p align=
"center">[
<a href=index.htm
>Index
</a> ]
</p>
131 <p align=
"center"><font face=
"Comic Sans MS"><small>This help is generated
22-Sep-
2005 by KOL Help generator, (C)
2000-
2001 by Vladimir Kladov
<br>Modified (C)
2003 by Alexander Bartov
</small></font></p>