I am currently working on an APL program for a class and have run into an issue with error handling.
In a function I made, I want to check to see that the input is an integer. If it is not, I want to return an error message and not run the rest of the function. So far, I compare to see if it's equal to the floor of itself. If not, I don't want the function to run and want it to stop. It works if I put 4.2
and gives an error message, but doesn't work if I put something like 'A'
in or 'ABCDEF'
and just gives a normal error. I tried making a try catch statement, but it gave me an error when it got to :Try
in my function.
Which isn't what I want. How can I make it so the function ends with an error message instead of continuing if the input is a character or string? I know I could put the entire code in an if block, but that seems really unnecessary.
My code in plain-text:
TESTER Q;error
:If Q≢⌊Q
'Possible'
:Else
'Not Possible'
:EndIf
'Again, Possible'
And as a screenshot: