initial commit
[rofl0r-KOL.git] / main_exception.htm
blob48243e9491aba743357ebecda2e6066acc2ec953
1 <html>
2 <head>
3 <title>KOL Help: Exception class (main frame)</title>
4 <base target="_top">
5 </head>
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
10 </b></font></p>
11 <p><b>
12 Exception = class( TObject )
13 </b></p>
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>
20 <p>
21 <font face="Courier" color="#800080"><b>property</b> <font color="#808000"><b>Message</b></font>: <b>string</b>;</font>
22 &nbsp;&nbsp;&nbsp;<font face="Webdings" size=7>&#209;</font>&nbsp;&nbsp;&nbsp;
23 <br>
24 Text string, containing descriptive message about the exception.
25 </p>
26 <a name="code"></a>
27 <p>
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 &nbsp;&nbsp;&nbsp;<font face="Webdings" size=7>&#209;</font>&nbsp;&nbsp;&nbsp;
30 <br>
31 Main exception code. This property can be used to determine, which exception
32 occure.
33 </p>
34 <a name="errorcode"></a>
35 <p>
36 <font face="Courier" color="#800080"><b>property</b> <font color="#808000"><b>ErrorCode</b></font>: <b>DWORD</b>;</font>
37 <br>
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.
41 </p>
42 <a name="exceptionrecord"></a>
43 <p>
44 <font face="Courier" color="#800080"><b>property</b> <font color="#808000"><b>ExceptionRecord</b></font>: PExceptionRecord;</font>
45 &nbsp;&nbsp;&nbsp;<font face="Webdings" size=7>&#209;</font>&nbsp;&nbsp;&nbsp;
46 <br>
47 This property is only for e_External exception.
48 </p>
49 <a name="data"></a>
50 <p>
51 <font face="Courier" color="#800080"><b>property</b> <font color="#808000"><b>Data</b></font>: <b>Pointer</b>;</font>
52 <br>
53 Custom defined pointer. Use it in your custom exceptions.
54 </p>
55 <h3 align="center"><font color="#FF8080">Exception methods</font></h3>
56 <a name="create"></a>
57 <p>
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>
59 <br>
60 Use this constructor to raise exception, which does not require of
61 argument formatting.
62 </p>
63 <a name="createfmt"></a>
64 <p>
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>
66 <br>
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.
70 </p>
71 <a name="createcustom"></a>
72 <p>
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>
74 <br>
75 Use this constructor to create e_Custom exception and to assign AError to
76 its <a href=#errorcode target="main">ErrorCode</a> property.
77 </p>
78 <a name="createcustomfmt"></a>
79 <p>
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>
81 <br>
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.
84 </p>
85 <a name="createresfmt"></a>
86 <p>
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>
88 <br>
89 </p>
90 <a name="destroy"></a>
91 <p>
92 <font face="Courier" color="#800080"><b>destructor</b> <font color="#808000"><b>Destroy</b></font>; <b>override</b>;</font>
93 <br>
94 destructor
95 </p>
96 <h3 align="center"><font color="#FF8080">Exception events</font></h3>
97 <a name="ondestroy"></a>
98 <p>
99 <font face="Courier" color="#800080"><b>property</b> <font color="#808000"><b>OnDestroy</b></font>: TDestroyException;</font>
100 <br>
101 This event is to allow to do something when custom Exception is
102 released.
103 </p>
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;
127 raise E;
128 </pre></b></font></p>
129 <hr>
130 <p align="center">[&nbsp;<a href=index.htm>Index</a>&nbsp;]</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>
132 </body>
133 </html>