Error trapping with Dyalog APL: Difference between revisions

Jump to navigation Jump to search
(→‎Misc: +Error-guards)
(One intermediate revision by the same user not shown)
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|Dfn error-guards]]
* [[Error trapping in Dyalog APL forms]]
== External links ==
=== Lessons ===
* Error handling webinars: [https://dyalog.tv/Webinar/?v=tDK0AKXXRAk part 1], [https://dyalog.tv/Webinar/?v=PSrXyk5tN6o part 2], [https://dyalog.tv/Webinar/?v=jkD-iQfjo_Q part 3], [https://dyalog.tv/Webinar/?v=G7Ht8iKvDMo part 4], [https://dyalog.tv/Webinar/?v=WP6R7VRmHfc part 5]
* [https://chat.stackexchange.com/rooms/52405/conversation/lesson-13-code-management-i-o-dates-unicode-files-errors#42339704 APL Cultivation]
=== Documentation ===
* [https://help.dyalog.com/latest/#Language/System%20Functions/signal.htm Signal Event]
* [https://help.dyalog.com/latest/#Language/Errors/APL%20Errors.htm Error messages]
* [https://help.dyalog.com/latest/#Language/System%20Functions/trap.htm Trap Event]
* [https://help.dyalog.com/latest/#Language/Control%20Structures/trap.htm Trap Statement]
* [https://help.dyalog.com/latest/#Language/System%20Functions/dm.htm Diagnostic Message]
* [https://help.dyalog.com/latest/#Language/System%20Functions/en.htm Event Number]


[[Category:Tutorials]][[Category:Dyalog APL examples]]
[[Category:Tutorials]][[Category:Dyalog APL examples]]
{{APL development}}

Navigation menu