Error trapping with Dyalog APL: Difference between revisions

Jump to navigation Jump to search
m
6 revisions imported: Migrate from miraheze
Miraheze>Adám Brudzewsky
(Created page with "To write bug-free code in a complex system and to forecast all errors is impossible. Therefore, implementing some kind of error trapping in an application which is supposed to...")
 
m (6 revisions imported: Migrate from miraheze)
(5 intermediate revisions by one other user not shown)
Line 68: Line 68:
=== Restarting the application ===
=== Restarting the application ===


For reasons explained in a minute we now have to define the “Restart the application” procedure. For this, for the first time we do not use the <source lang=apl inline>'E' statement but the <source lang=apl inline>'C'</source> statement. The ''C'' is short for ''Cut back''. This instructs APL to cut the status indicator back to the level where <source lang=apl inline>⎕TRAP</source> '''is localized''' – that is not  necessarily where it was set – and execute the expression in the 3rd argument there. However, if <source lang=apl inline>⎕TRAP</source> is not localized at all, i.e. it is in the workspace, the status indicator is cut back completely and the expression is executed in the workspace.
For reasons explained in a minute we now have to define the “Restart the application” procedure. For this, for the first time we do not use the <source lang=apl inline>'E'</source> statement but the <source lang=apl inline>'C'</source> statement. The ''C'' is short for ''Cut back''. This instructs APL to cut the status indicator back to the level where <source lang=apl inline>⎕TRAP</source> '''is localized''' – that is not  necessarily where it was set – and execute the expression in the 3rd argument there. However, if <source lang=apl inline>⎕TRAP</source> is not localized at all, i.e. it is in the workspace, the status indicator is cut back completely and the expression is executed in the workspace.
<source lang=apl>
<source lang=apl>
⎕TRAP,←⊂(#.Events.RestartAppl 'C' '→∆Restart')
⎕TRAP,←⊂(#.Events.RestartAppl 'C' '→∆Restart')
Line 141: Line 141:
The best idea, however, is to use <source lang=apl inline>⎕NEXISTS</source> to check the file for already being created. In general it is a good idea to use error trapping only for extraordinary problems.
The best idea, however, is to use <source lang=apl inline>⎕NEXISTS</source> to check the file for already being created. In general it is a good idea to use error trapping only for extraordinary problems.


=== <source lang=apl inline>⎕SIGNAL</source> ===
=== The <source lang=apl inline>⎕SIGNAL</source> system function ===


Note that an event which is <source lang=apl inline>⎕SIGNAL</source>led can be intercepted with <source lang=apl inline>⎕TRAP</source> but not <source lang=apl inline>:Trap</source>
Note that an event which is <source lang=apl inline>⎕SIGNAL</source>led can be intercepted with <source lang=apl inline>⎕TRAP</source> but not <source lang=apl inline>:Trap</source>
Line 191: Line 191:
== Code ==
== Code ==


<div class="toccolours mw-collapsible mw-collapsed">
{{Collapse|The below workspace contains all the code needed to implement the ideas discussed above.|<source lang=apl>
The below workspace contains all the code needed to implement the ideas discussed above.
<div class="mw-collapsible-content">
<source lang=apl>
(⎕IO ⎕ML ⎕WX)←1 1 3
(⎕IO ⎕ML ⎕WX)←1 1 3


Line 769: Line 766:
:EndNamespace
:EndNamespace
</source>
</source>
</div>
}}
</div>
 
[[Category:Tutorials]]

Navigation menu