Skip to content

Commit

Permalink
Add a LOCAL ERROR handler to FNwimperror_program.
Browse files Browse the repository at this point in the history
Following discussion on ROOL Forum, add a LOCAL ERROR handler to
FNwimperror_program, so that any errors in the error handling don't
cause an infinite loop.
  • Loading branch information
steve-fryatt committed Dec 26, 2021
1 parent 93af8ca commit cd99bec
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Chapters/ch01-an-example-application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ ENDPROC</code>

<code id="list-example-app-error" lang="bbcbasic" title="The Wimp error handling code">DEF FNwimperror_program
LOCAL result%
LOCAL ERROR

REM An error in the error hander will cause the application to print a brief
REM message out on screen, then exit immediately.

ON ERROR LOCAL VDU 4 : PRINT &quot;Error in error handler (&quot;;REPORT$;&quot;; error code &quot;;ERL;&quot;)&quot; : END

REM With the emergency error handler in place, now handle the original error.

SYS &quot;Hourglass_Smash&quot;

Expand All @@ -113,7 +121,7 @@ SYS &quot;Wimp_ReportError&quot;, q%, &amp;0703, TaskName$, TaskSprite$, 1, 0 TO

=(result% = 2)</code>

<p>In the event of an error, <swi>Hourglass_Smash</swi> is called to ensure that the hourglass is cleared, then <swi>Wimp_ReportError</swi> is used to report the problem to the user. Since this is called from <code>ON&nbsp;ERROR</code>, the expectation is that <code>REPORT$</code> and <code>ERL</code> will have useful values.</p>
<p>In the event of an error, <swi>Hourglass_Smash</swi> is called to ensure that the hourglass is cleared, then <swi>Wimp_ReportError</swi> is used to report the problem to the user. Since this is called from <code>ON&nbsp;ERROR</code>, the expectation is that <code>REPORT$</code> and <code>ERL</code> will have useful values. To be on the safe side, a local error hander is set up to catch any further errors and exit cleanly without going into an infinite loop. The original error handler, stacked by <code>LOCAL ERROR</code>, is restored when the function exits.</p>

<p>Finally, <function>PROCpoll</function> is called repeatedly to handle the calls to <swi>Wimp_Poll</swi>; the code can be seen in <reference id="list-example-app-poll" />.</p>

Expand Down
Binary file modified Downloads/Chapter01/ExampleApp/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter02/SideBox1/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter02/SideBox2/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter03/TopBar1/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter03/TopBar2/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter03/TopBar3/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter03/TopBar4/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter04/ColHead1/!PaneDemo/!RunImage,ffb
Binary file not shown.
Binary file modified Downloads/Chapter04/ColHead2/!PaneDemo/!RunImage,ffb
Binary file not shown.

0 comments on commit cd99bec

Please sign in to comment.