summaryrefslogtreecommitdiffstats
path: root/helpcontent2/source/text/sbasic/shared/03/sf_exception.xhp
blob: 416c43457ae543afae6a3b9aa9fabda4db519bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
   <!--
   * This file is part of the LibreOffice project.
   *
   * This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this
   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   *
   -->

<meta>
  <topic id="SF_Exception" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">ScriptForge.Exception service (SF_Exception)</title>
    <filename>/text/sbasic/shared/03/sf_exception.xhp</filename>
  </topic>
</meta>
<body>
<section id="abstract">
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id381587139303941">
    <bookmark_value>Exception service</bookmark_value>
  </bookmark>
  <h1 id="hd_id521580038927003" xml-lang="en-US"><variable id="ExceptionService"><link href="text/sbasic/shared/03/sf_exception.xhp" name="Exception service"><literal>ScriptForge</literal>.<literal>Exception</literal> service</link></variable></h1>
  <paragraph role="paragraph" id="par_id181587139648008" xml-lang="en-US">The <literal>Exception</literal> service is a collection of methods to assist in code debugging in Basic and Python scripts and in error handling in Basic scripts.</paragraph>
  <paragraph role="paragraph" id="par_id141587140927573" xml-lang="en-US">In <emph>Basic scripts</emph>, when a run-time error occurs, the methods and properties of the <literal>Exception</literal> service help identify the error context and allow to handle it.</paragraph>
</section>
  <list type="unordered">
    <listitem>
      <paragraph id="par_id401621450898070" role="listitem">The <literal>SF_Exception</literal> service is similar to the <link href="text/sbasic/shared/ErrVBA.xhp" name="VBA Err object">VBA <literal>Err</literal> object</link>.</paragraph>
    </listitem>
    <listitem>
      <paragraph id="par_id361621450908874" role="listitem">The <literal>Number</literal> property identifies the error.</paragraph>
    </listitem>
    <listitem>
      <paragraph id="par_id861621450910254" role="listitem">Use the <literal>Raise</literal> method to interrupt processing. The <literal>RaiseWarning</literal> method can be used to trap an anomaly without interrupting the macro execution.</paragraph>
    </listitem>
  </list>
  <tip id="par_id621587225732733" xml-lang="en-US">Errors and warnings raised with the <literal>Exception</literal> service are stored in memory and can be retrieved using the <literal>Console</literal> method.</tip>

  <paragraph role="paragraph" id="par_id411587141146677" xml-lang="en-US">The <literal>Exception</literal> service console stores events, variable values and information about errors. Use the console when the Basic IDE is not easily accessible, for example in <link href="text/scalc/guide/userdefined_function.xhp" name="Calc user-defined function">Calc user defined functions (UDF)</link> or during events processing.</paragraph>
  <paragraph role="paragraph" id="par_id251621034725811">Use the <literal>DebugPrint</literal> method to add any relevant information to the console. Console entries can be dumped to a text file or visualized in a dialog window.</paragraph>
  <paragraph role="paragraph" id="par_id111587141158495" xml-lang="en-US">When an error occurs, an application macro may:</paragraph>
  <list type="ordered">
    <listitem><paragraph role="paragraph" id="par_id451587141202844" xml-lang="en-US">Report the error in the <literal>Exception</literal> console</paragraph></listitem>
    <listitem><paragraph role="paragraph" id="par_id751587141235313" xml-lang="en-US">Inform the user about the error using either a standard message or a custom message</paragraph></listitem>
    <listitem><paragraph role="paragraph" id="par_id931587141260777" xml-lang="en-US">Optionally stop its execution</paragraph></listitem>
  </list>
  <paragraph role="paragraph" id="par_id771621035263403">In <emph>Python scripts</emph> the <literal>Exception</literal> service is mostly used for debugging purposes. Methods such as <literal>DebugPrint</literal>, <literal>Console</literal> and <literal>DebugDisplay</literal> are useful to quickly print messages, log data and open the console window from within a Python script.</paragraph>
  <note id="par_id211621035276160">Not all methods and properties are available for Python scripts since the Python language already has a comprehensive exception handling system.</note>

  <h2 id="hd_id201586594659135" xml-lang="en-US">Service invocation</h2>
  <embed href="text/sbasic/shared/00000003.xhp#In_Basic"/>
  <paragraph role="paragraph" id="par_id161610652161795">The following examples show three different approaches to call the method <literal>Raise</literal>. All other methods can be executed in a similar fashion.</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id881610652359633">SF_Exception.Raise(...)</paragraph>
  </bascode>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id441586594733346">Dim exc : exc = SF_Exception</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id481586594739978">exc.Raise(...)</paragraph>
  </bascode>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id431586594750461">Dim exc : exc = CreateScriptService("Exception")</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id471586594758689">exc.Raise(...)</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#In_Python"/>
  <paragraph role="paragraph" id="par_id901621036227048">The code snippet below creates an instance of the <literal>Exception</literal> service, logs a message and displays the <literal>Console</literal> window.</paragraph>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id651621036305969">from scriptforge import CreateScriptService</paragraph>
    <paragraph role="pycode" localize="false" id="pyc_id101621036327340">exc = CreateScriptService("Exception")</paragraph>
    <paragraph role="pycode" localize="false" id="pyc_id71621036480430">someVar = 100</paragraph>
    <paragraph role="pycode" localize="false" id="pyc_id291621036366532">exc.DebugPrint("Value of someVar", someVar)</paragraph>
    <paragraph role="pycode" localize="false" id="pyc_id411621036455976">exc.Console()</paragraph>
  </pycode>

  <h2 id="hd_id651584978211886" xml-lang="en-US">Properties</h2>
  <paragraph role="paragraph" id="par_id911621036526404">The properties listed below are only available for <emph>Basic</emph> scripts.</paragraph>
  <table id="tab_id761584978211275">
    <tablerow>
      <tablecell>
        <paragraph id="par_id271584978211792" role="tablehead">Name</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id241584978211550" role="tablehead">Readonly</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id621584978211403" role="tablehead">Description</paragraph>
      </tablecell>
    </tablerow>
    <tablerow>
      <tablecell>
        <paragraph id="par_id581584978715552" role="tablecontent" localize="false">Description</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id71584978715562" role="tablecontent" xml-lang="en-US">No</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id581584978715701" role="tablecontent" xml-lang="en-US">The error message text.</paragraph>
        <paragraph role="paragraph" id="par_id241610652688334">Default value is "" or a string containing the Basic run-time error message.</paragraph>
      </tablecell>
    </tablerow>
    <tablerow>
      <tablecell>
        <paragraph id="par_id91584978211231" role="tablecontent" localize="false">Number</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id211584978211383" role="tablecontent" xml-lang="en-US">No</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id691584978211774" role="tablecontent" xml-lang="en-US">The code of the error. It can be a numeric value or text.</paragraph>
        <paragraph role="paragraph" id="par_id151610652632828">Default value is 0 or the numeric value corresponding to the Basic run-time error code.</paragraph>
      </tablecell>
    </tablerow>
    <tablerow>
      <tablecell>
        <paragraph id="par_id1001584978666440" role="tablecontent" localize="false">Source</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id671584978666689" role="tablecontent" xml-lang="en-US">No</paragraph>
      </tablecell>
      <tablecell>
        <paragraph id="par_id951584978666296" role="tablecontent" xml-lang="en-US">The location in the code where the error occurred. It can be a numeric value or text.</paragraph>
        <paragraph role="paragraph" id="par_id681610652723345">Default value is 0 or the code line number for a standard Basic run-time error.</paragraph>
      </tablecell>
    </tablerow>
  </table>
  <tip id="par_id461584978880380" xml-lang="en-US">Raising or clearing an <literal>Exception</literal> resets its properties.</tip>
  <embed href="text/sbasic/shared/ErrVBA.xhp#RestrictedErrorCodes"/>

  <table id="tab_id441608131596153">
    <tablerow>
      <tablecell colspan="3"><paragraph id="par_id881608131596153" role="tablehead">List of Methods in the Exception Service</paragraph></tablecell>
    </tablerow>
    <tablerow>
      <tablecell>
        <paragraph id="par_id461608131596153" role="tablecontent" localize="false">
          <link href="text/sbasic/shared/03/sf_exception.xhp#Clear" name="Clear method">Clear</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#Console" name="Console method">Console</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#ConsoleClear" name="ConsoleClear method">ConsoleClear</link>
        </paragraph>
      </tablecell>
      <tablecell>
        <paragraph role="tablecontent" id="par_id871608132025242" localize="false">
          <link href="text/sbasic/shared/03/sf_exception.xhp#ConsoleToFile" name="ConsoleToFile method">ConsoleToFile</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#DebugDisplay" name="DebugDisplay method">DebugDisplay</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#DebugPrint" name="DebugPrint method">DebugPrint</link><br/><br/>
        </paragraph>
      </tablecell>
      <tablecell>
        <paragraph role="tablecontent" id="par_id831608132069033" localize="false">
          <link href="text/sbasic/shared/03/sf_exception.xhp#PythonPrint" name="PythonPrint method">PythonPrint</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#PythonShell" name="PythonShell method">PythonShell</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#Raise" name="Raise method">Raise</link><br/>
          <link href="text/sbasic/shared/03/sf_exception.xhp#RaiseWarning" name="RaiseWarning method">RaiseWarning</link><br/>
        </paragraph>
      </tablecell>
    </tablerow>
  </table>

<section id="Clear">
  <comment> Clear -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id121582203710297">
    <bookmark_value>Exception service;Clear</bookmark_value>
  </bookmark>
  <h2 id="hd_id791579683635979" localize="false">Clear</h2>
  <paragraph role="paragraph" id="par_id271579683706571">Resets the current error status and clears the <literal>SF_Exception</literal> properties.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#Basic_Only"/>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id531579684617249">SF_Exception.Clear()</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <paragraph role="paragraph" id="par_id701610654263121">The following example shows how to catch a division-by-zero exception, whose error code is 11.</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id631579688532444">Sub Example_Clear()</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id721587215452594">    Dim a, b, c</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id431587221926496">    On Local Error GoTo Catch</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id541601735163562">    Try:</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id441587215463149">        a = 10 : b = 0</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id531587215470406">        c = a / b</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id361587215477209">        '...</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id931587215483393">        Exit Sub</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id851587215489779">    Catch:</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id771587215496761">        If SF_Exception.Number = 11 Then SF_Exception.Clear()</paragraph>
    <paragraph role="bascode" id="bas_id51587215508130"  xml-lang="en-US">        'If division by zero, ignore the error</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id801579688542131">End Sub</paragraph>
  </bascode>
  <tip id="par_id201610654368082">For a complete list of Basic run-time error codes, refer to <link href="text/sbasic/shared/01030300.xhp" name="Run-Time Error Codes">Debugging a Basic Program</link>.</tip>
</section>

<section id="Console">
  <comment> Console -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id9159871817936">
    <bookmark_value>Exception service;Console</bookmark_value>
  </bookmark>
  <h2 id="hd_id971598718179751" localize="false">Console</h2>
  <paragraph role="paragraph" id="par_id651598718179382">Displays the console messages in a modal or non-modal dialog. In both modes, all the past messages issued by a <literal>DebugPrint()</literal> method or resulting from an exception are displayed. In non-modal mode, subsequent entries are added automatically.</paragraph>
  <paragraph role="paragraph" id="par_id161598718286205" xml-lang="en-US">If the console is already open, when non-modal, it is brought to the front.</paragraph>
  <paragraph role="paragraph" id="par_id801598718629151" xml-lang="en-US">A modal console can only be closed by the user. A non-modal console can either be closed by the user or upon macro termination.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="paragraph" localize="false" id="par_id571621040248589">
    <input>exc.Console(modal: bool = True)</input>
  </paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id511598718179819"><emph>modal</emph>: Determine if the console window is modal (<literal>True</literal>) or non-modal (<literal>False</literal>). Default value is <literal>True</literal>.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <embed href="text/sbasic/shared/00000003.xhp#In_Basic"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id78159871817999">    SF_Exception.Console(Modal := False)</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#In_Python"/>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id621621040451660">exc.Console(modal = False)</paragraph>
  </pycode>
</section>

<section id="ConsoleClear">
  <comment> ConsoleClear -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id621587215098307">
    <bookmark_value>Exception service;ConsoleClear</bookmark_value>
  </bookmark>
  <h2 id="hd_id671587215098845" localize="false">ConsoleClear</h2>
  <paragraph role="paragraph" id="par_id641587215098903">Clears the console keeping an optional number of recent messages. If the console is activated in non-modal mode, it is refreshed.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="paragraph" localize="false" id="par_id651621040714152">
    <input>exc.ConsoleClear(keep: int = 0)</input>
  </paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id351587215098527"><emph>keep</emph>: The number of recent messages to be kept. Default value is 0.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <paragraph role="paragraph" id="par_id521610655023824">The following example clears the console keeping the 10 most recent messages.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#In_Basic"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id981587215098452">    SF_Exception.ConsoleClear(10)</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#In_Python"/>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id891621040671870">exc.ConsoleClear(10)</paragraph>
  </pycode>
</section>

<section id="ConsoleToFile">
  <comment> ConsoleToFile -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id911587218077199">
    <bookmark_value>Exception service;ConsoleToFile</bookmark_value>
  </bookmark>
  <h2 id="hd_id691587218077803" localize="false">ConsoleToFile</h2>
  <paragraph role="paragraph" id="par_id281587218077400">Exports the contents of the console to a text file. If the file already exists and the console is not empty, it will be overwritten without warning. Returns <literal>True</literal> if successful.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="paragraph" localize="false" id="par_id171621042623495">
    <input>exc.ConsoleToFile(filename: str): bool</input>
  </paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id851587218077862"><emph>filename</emph>: The name of the text file the console should be dumped into. The name is expressed according to the current <literal>FileNaming</literal> property of the <literal>SF_FileSystem</literal> service. By default, <link href="text/sbasic/shared/00000002.xhp" name="Url notation">URL notation</link> and the native operating system's format are both admitted.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <embed href="text/sbasic/shared/00000003.xhp#In_Basic"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id941587218077971">    SF_Exception.ConsoleToFile("C:\Documents\myFile.txt")</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#In_Python"/>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id901621041580099">exc.ConsoleToFile(r"C:\Documents\myFile.txt")</paragraph>
  </pycode>
</section>

<section id="DebugDisplay">
  <comment> DebugDisplay -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id591587218637462">
    <bookmark_value>Exception service;DebugDisplay</bookmark_value>
  </bookmark>
  <h2 id="hd_id691587218077177" localize="false">DebugDisplay</h2>
  <paragraph role="paragraph" id="par_id701621043185177">Concatenates all the arguments into a single human-readable string and displays it in a <literal>MsgBox</literal> with an Information icon and an OK button.</paragraph>
  <paragraph role="paragraph" id="par_id791621097689492">The final string is also added to the Console.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="paragraph" localize="false" id="par_id461621042840877">
    <input>exc.DebugDisplay(arg0: any, [arg1: any, ...])</input>
  </paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id481587218636884"><emph>arg0[, arg1, ...]</emph>: Any number of arguments of any type.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <embed href="text/sbasic/shared/00000003.xhp#In_Basic"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id871621043432964">SF_Exception.DebugDisplay("Current Value", someVar)</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#In_Python"/>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id501621043522869">exc.DebugDisplay("Current Value", someVar)</paragraph>
  </pycode>
</section>

<section id="DebugPrint">
  <comment> DebugPrint -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id591587218637462">
    <bookmark_value>Exception service;DebugPrint</bookmark_value>
  </bookmark>
  <h2 id="hd_id981587218637683" localize="false">DebugPrint</h2>
  <paragraph role="paragraph" id="par_id281587218637490">Assembles all the given arguments into a single human-readable string and adds it as a new entry in the console.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="paragraph" localize="false" id="par_id461621042840764">
    <input>exc.DebugPrint(arg0: any, [arg1: any, ...])</input>
  </paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id481587218637988"><emph>arg0[, arg1, ...]</emph>: Any number of arguments of any type.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <embed href="text/sbasic/shared/00000003.xhp#In_Basic"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id58158721863732">SF_Exception.DebugPrint(Null, Array(1, 2, 3), "line1" &amp; Chr(10) &amp; "Line2", DateSerial(2020, 04, 09))</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id151610655617295">' [NULL]   [ARRAY] (0:2) (1, 2, 3)  line1\nLine2  2020-04-09</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#In_Python"/>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id591621043074050">exc.DebugPrint(None, [1, 2, 3], "line1\nline2")</paragraph>
    <paragraph role="pycode" localize="false" id="pyc_id161621098073293"># None  [1, 2, 3]  line1\nline2</paragraph>
  </pycode>
</section>

<section id="PythonPrint">
  <comment> PythonPrint -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id301587219428104">
    <bookmark_value>Exception service;PythonPrint</bookmark_value>
  </bookmark>
  <h2 id="hd_id5515879128204789" localize="false">PythonPrint</h2>
  <paragraph role="paragraph" id="par_id111621624672183">Displays the list of arguments in a readable form in the Python shell (APSO) console. Arguments are separated by a TAB character (simulated by spaces).</paragraph>
  <paragraph role="paragraph" id="par_id841621426229467">The same string is added to the ScriptForge debug console.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#Basic_Only"/>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <bascode>
  <paragraph role="bascode" localize="false" id="bas_id81630591881423">exc.PythonPrint(arg0: any, [arg1: any, ...])</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#Requires_APSO"/>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id391126449167833"><emph>arg0[, arg1, ...]</emph>: Any number of arguments of any type. The maximum length of each individual argument is 1024 characters.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="pyc_id451621479450230">exc.PythonPrint(a, Array(1, 2, 3), , &quot;line1&quot; &amp; Chr(10) &amp; &quot;Line2&quot;, DateSerial(2020, 04, 09))</paragraph>
  </bascode>
  <note id="par_id261123015276160">In python use simply the builtin print() statement.</note>
</section>

<section id="PythonShell">
  <comment> PythonShell -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id301587219824104">
    <bookmark_value>Exception service;PythonShell</bookmark_value>
  </bookmark>
  <h2 id="hd_id5515872198204789" localize="false">PythonShell</h2>
  <paragraph role="paragraph" id="par_id111621426672183">Opens an APSO Python shell as a non-modal window. The Python script keeps running after the shell is opened. The output from <literal>print</literal> statements inside the script are shown in the shell.</paragraph>
  <paragraph role="paragraph" id="par_id841621426922467">Only a single instance of the APSO Python shell can be opened at any time. Hence, if a Python shell is already open, then calling this method will have no effect.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#Requires_APSO"/>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="paragraph" localize="false" id="par_id411621625580764">
    <input>exc.PythonShell(variables: dict)</input>
  </paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <paragraph role="paragraph" id="par_id391621449167833"><emph>variables</emph>: a Python dictionary with variable names and values that will be passed on to the APSO Python shell. By default all local variables are passed using Python's builtin <literal>locals()</literal> function.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <paragraph role="paragraph" id="par_id991621449657850">The example below opens the APSO Python shell passing all global and local variables considering the context where the script is running.</paragraph>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id451621449750230">exc.PythonShell({**globals(), **locals()})</paragraph>
  </pycode>
  <paragraph role="paragraph" id="par_id521621449800348">When the APSO Python shell is open, any subsequent output printed by the script will be shown in the shell. Hence, the string printed in the example below will be displayed in the Python shell.</paragraph>
  <pycode>
    <paragraph role="pycode" localize="false" id="pyc_id441621449844658">exc.PythonShell()</paragraph>
    <paragraph role="pycode" id="pyc_id731621449899901">print("Hello world!")</paragraph>
  </pycode>
</section>

<section id="Raise">
  <comment> Raise -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id301587219824932">
    <bookmark_value>Exception service;Raise</bookmark_value>
  </bookmark>
  <h2 id="hd_id551587219824275" localize="false">Raise</h2>
  <paragraph role="paragraph" id="par_id541587219824771">Generates a run-time error. An error message is displayed to the user and reported in the console. The execution is stopped. The <literal>Raise()</literal> method can be placed inside the normal script flow or in a dedicated error-handling routine.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#Basic_Only"/>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id29158721982455">SF_Exception.Raise([Number As Variant], [Source As Variant], [Description As String])</paragraph>
  </bascode>
  <paragraph role="paragraph" id="par_id921587220542454" xml-lang="en-US">The code snippets presented next are equivalent. They show alternative ways to raise an exception with code 2100.</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id881587220508733">SF_Exception.Raise(2100)</paragraph>
  </bascode>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id361587220516558">SF_Exception.Number = 2100</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id51587220525168">SF_Exception.Raise()</paragraph>
  </bascode>
  <bascode>
    <paragraph role="bascode" id="bas_id491608216264445" localize="false">SF_Exception.Raise Number := 2100</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <section id="Raise_Parameters">
  <paragraph role="paragraph" id="par_id851587219824597"><emph>Number</emph>: The error code, as a number or as a string. Default value is that of <literal>Err</literal> Basic builtin function.</paragraph>
  <paragraph role="paragraph" id="par_id461587220986452" xml-lang="en-US"><emph>Source</emph>: The location of the error, as a number or as a string. Default value is that of <literal>Erl</literal> Basic builtin function.</paragraph>
  <paragraph role="paragraph" id="par_id721587221018162" xml-lang="en-US"><emph>Description</emph>: The message to display to the user and to report in the console. Default value is that of <literal>Error$</literal> Basic builtin function.</paragraph>
  </section>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id101587221964367">Sub Example_Raise()</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id681587221964375">    Dim a, b, c</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id811587221964318">    On Local Error GoTo Catch</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id511601735068745">    Try:</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id831587221964580">        a = 10 : b = 0</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id4115872219641">        c = a / b</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id85158722196499">        '...</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id241587221964418">        Exit Sub</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id721587221964962">    Catch:</paragraph>
    <paragraph role="bascode" id="bas_id211587222852310" xml-lang="en-US">        'See variants below ...</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id61587221964946">End Sub</paragraph>
  </bascode>
  <paragraph role="paragraph" id="par_id111587222580987" xml-lang="en-US">To raise an exception with the standard values:</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id341587222627299">Catch:</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id261587222635009">    SF_Exception.Raise()</paragraph>
  </bascode>
  <paragraph role="paragraph" id="par_id751587222598238" xml-lang="en-US">To raise an exception with a specific code:</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id421587222644102">Catch:</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id171587222653391">    SF_Exception.Raise(11)</paragraph>
  </bascode>
  <paragraph role="paragraph" id="par_id501587222607771" xml-lang="en-US">To replace the usual message:</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id721587222663630">Catch:</paragraph>
    <paragraph role="bascode" xml-lang="en-US" id="bas_id431587222670849">    SF_Exception.Raise(, , "It is not a good idea to divide by zero.")</paragraph>
  </bascode>
  <paragraph role="paragraph" id="par_id611587222617174" xml-lang="en-US">To raise an application error:</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id441587222684053">Catch:</paragraph>
    <paragraph role="bascode" xml-lang="en-US" id="bas_id71587222694657">    SF_Exception.Raise("MyAppError", "Example_Raise()", "Something wrong happened !")</paragraph>
  </bascode>
</section>

<section id="RaiseWarning">
  <comment> RaiseWarning -------------------------------------------------------------------------------------------------------------------------- </comment>
  <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id811587224839918">
    <bookmark_value>Exception service;RaiseWarning</bookmark_value>
  </bookmark>
  <h2 id="hd_id391587224839449" localize="false">RaiseWarning</h2>
  <paragraph role="paragraph" id="par_id1001587224839900" xml-lang="en-US">This method has exactly the same syntax, arguments and behavior as the <literal>Raise()</literal> method.</paragraph>
  <paragraph role="paragraph" id="par_id761587224839624" xml-lang="en-US">However, when a warning is raised, <emph>the macro execution is not stopped</emph>.</paragraph>
  <embed href="text/sbasic/shared/00000003.xhp#Basic_Only"/>
  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id25197821982455">SF_Exception.RaiseWarning([Number As Variant], [Source As Variant], [Description As String])</paragraph>
  </bascode>
  <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
  <embed href="text/sbasic/shared/03/sf_exception.xhp#Raise_Parameters"/>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id71587222649657">SF_Exception.RaiseWarning(Source:="Example_Raise()", _</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id841608217948025">    Description:="Something wrong happened !", _</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id361608217956289">    Number:="MyAppError")</paragraph>
  </bascode>
</section>

<section id="relatedtopics">
  <embed href="text/sbasic/shared/03050000.xhp#ErrHandlingh1"/>
</section>

</body>
</helpdocument>