Error trapping with Dyalog APL: Difference between revisions

Jump to navigation Jump to search
no edit summary
(→‎Misc: +Error-guards)
No edit summary
Line 188: Line 188:


But even in such a case the problem should be communicated. I found the idea of a watchdog application very useful, which, among other tasks, is listening to UDP telegrams on a particular port. An application in trouble can then send a telegram to the watchdog, telling about the problem. Using a type of error class, the client can tell the watchdog about the seriousness of the problem, and the watchdog can then decide to simply display it on it's GUI or send a SMS message or/and an email to the admin.
But even in such a case the problem should be communicated. I found the idea of a watchdog application very useful, which, among other tasks, is listening to UDP telegrams on a particular port. An application in trouble can then send a telegram to the watchdog, telling about the problem. Using a type of error class, the client can tell the watchdog about the seriousness of the problem, and the watchdog can then decide to simply display it on it's GUI or send a SMS message or/and an email to the admin.
=== Error-guards in dfns ===
[[dfn|Direct functions]] in Dyalog APL support error-guards for processing errors by error codes.<ref>[https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Error%20Guards.htm Error Guards] – Dyalog APL.</ref>
In the following example, there are two error-guards for the error code 11 (DOMAIN ERROR):<ref>[https://help.dyalog.com/latest/#Language/Errors/APL%20Errors.htm#APLErrors APL Error Messages and Codes] – Dyalog APL.</ref>
<source lang=apl>
gravity←{
    G←6.6743E¯11 ⍝ gravitational constant
    11::'N/A'    ⍝ second DOMAIN ERROR: return 'N/A'
    11::G×(⍎1⊃⍵)×(⍎2⊃⍵)÷(⍎3⊃⍵)*2  ⍝ first DOMAIN ERROR: maybe the argument is a vector of strings?
    G×⍵[1]×⍵[2]÷⍵[3]*2            ⍝ the argument is a vector of numbers
}
      ⍝ Calculate gravity force between the Earth and the Sun
      gravity '1.99e30' '5.97e24' '1.50e11'
3.524119391E22
      gravity 1.99e30 5.97e24 1.50e11
3.524119391E22
      gravity 1.99e30 5.97e24 0  ⍝ trigger division by zero
N/A
</source>


== Code ==
== Code ==
Line 789: Line 768:
</source>
</source>
}}
}}
== See also ==
* [[Dfn#Error-guards]]


[[Category:Tutorials]][[Category:Dyalog APL examples]]
[[Category:Tutorials]][[Category:Dyalog APL examples]]

Navigation menu