1

How to use Try/Except in APL

Using :Trap is not working, Why and how to fix?

Code:

∇F←R
:Trap
⎕←1÷0
:Catch
⎕←'Error'
:EndTrap
F←0
∇
R
Fmbalbuena
  • 95
  • 1
  • 12

1 Answers1

-2

Use this

∇F←R
:Trap 1
⎕←1÷0
:Catch
⎕←'Error'
:EndTrap
F←0
∇
R

Instead of

∇F←R
:Trap
⎕←1÷0
:Catch
⎕←'Error'
:EndTrap
F←0
∇
R

:Trap always need right argument

Fmbalbuena
  • 95
  • 1
  • 12
  • 1
    This isn't correct. Did you even test it? As per [the documentation](https://help.dyalog.com/latest/#Language/Control%20Structures/trap.htm) `:Trap` takes a list of error numbers. Error number 1 will *not* catch division-by-zero errors. To catch *all* errors, you have to use the special code 0. Furthermore, there's no such thing as `:Catch`; it is `:Else` for all errors, and `:Case n` for a single error; `:CaseList n` for multiple. – Adám Jan 10 '22 at 06:52