APLX Help : Help on APL language : Errors : Overview of error handling and the State Indicator
|
|
![]() |
Overview of error handling and the State Indicator |
Errors in calculator modeIf you enter a statement containing an error in calculator mode, APL responds with an error message. For example, if you attempt an operation on unsuitable data, you normally get a domain error: 1 1 0 11 ∨ 1 1 0 0 DOMAIN ERROR 1 1 0 11 ∨ 1 1 0 0 ^ This error has occurred because the OR primitive function operates only on values 0 and 1, not 11 as supplied in the left argument. As the example shows, the statement containing the error is displayed with an error indicator ( To correct an error in calculator mode, simply retype the statement correctly, or alternatively use the recall-line key (usually Ctrl-Up Arrow, or Cmd-Up Arrow on the Macintosh) to recal1 the statement, then edit it and re-enter it. In most versions of APLX, you can also correct it directly in the window, and then press Return or Enter to re-evaluate it. Errors in user-defined functions or operatorsIf an error is encountered during execution of a user-defined function or operator, execution stops at that point. The appropriate error message is displayed in the session window, followed on a separate line, by the name of the function containing the error, the line number at which execution stopped and the statement itself: LENGTH ERROR CALC[2] R←(X,Y)-1 2 3 ^ The above example shows that execution stopped in function The Debug WindowAs well as displaying the error in the Session Window, desktop editions of APLX will normally display the Debug Window if an error occurs in a user-defined function, operator, or class method. This shows the function or operator in which the error occurred, and allows you to edit the line immediately and continue: ![]() In this example, an error has occurred on line 13 of the function, so execution has stopped there. Normally you would edit the incorrect line in situ (in this case correcting the spelling mistake 'jeva' instead of 'java'), and then press the Run button (the solid triangular arrow) to continue execution. You can also resume at a different line (by dragging the small green position indicator, currently on line 13, or by using the 'Resume at line' control), or abandon the function by pressing the Quit (red cross) button. InterruptsA function or operator can also be halted by the user hitting the interrupt key (usually Ctrl-Break on Windows, Cmd-Period on the Macintosh, or Ctrl-C under Linux). A single interrupt causes APLX to complete the line of code it is executing before stopping. Two interrupts in quick succession cause it to stop as soon as it can, even if it is executing a single calculation which takes a long time (for example inverting a matrix with Again, on desktop editions of APLX, the Debug window will appear if you interrupt a user-defined function, operator or method. The State IndicatorIt may be that the function at which execution halted was called by another function. You can inspect a system variable called ⎕SI C[2] * B[8] A[5] This display (often referred to as the 'SI Stack') tells you that function The asterisk on the first line means that the function named on that line is 'suspended'. The other functions are 'pendent'; their execution cannot be resumed till execution of function C is completed. If at this point you executed another function, E[3] * D[6] C[2] * B[8] A[5] Effectively it contains records of two separate sequences of events; E[3] * D[6] ------------------- C[2] * B[8] A[5] You can clear the top level of the state indicator (i.e. the record of the most recent sequence) by entering the branch symbol → ⎕SI C[2] * B[8] A[5] In this example, another Alternatively, you can clear the entire state indicator at any stage by using the system command Action after suspended executionIf you want to resume execution at the point where it stopped you can do so from the Debug Window as described above, or by using the symbol →3 A system variable →⎕CL You don't have to continue from the point where execution was suspended. You can specify a line other than the current line: →4 or →⎕CL+1 Equally, you can specify execution of a different function. Editing suspended and pendent functionsWhat's perhaps most likely after an error in execution of a function is that you'll want to edit the function containing the error. (It's marked with It is possible that after editing the function you may get this message: SI DAMAGE This indicates that you've done something which makes it impossible for the original sequence of execution to be resumed. No action is necessary other than to use the system command What you cannot do after a halt in execution is to edit any of the pendent functions. They are the functions in the state indicator display that are not marked with an asterisk: ⎕SI E[3] * D[6] C[2] * B[8] A[5] An attempt to edit a pendent function using the Del editor will produce a ∇A DEFN ERROR ∇A ^ Similarly, you can edit the function using If you want to edit a pendent function, simply clear the state indicator using Error trappingYou can specify in advance what should happen if an error occurs during execution, in which case that error will not cause execution to stop. For example, if you wrote a function which invited the user to type in some numeric data, you might foresee the possibility that he or she would type non-numeric data instead. This would cause an error. APLX allows you to 'trap' the error at runtime. There are two main ways of doing this:
APLX also implements the older In general, it is probably best not to mix different styles of error-trapping in a single function. However, if you do, and an error occurs in a line where more than one error trap is live, then the error trap which will take effect is the first of:
Error-related system functionsA number of system functions are available for finding out where an error occurred and why, or for simulating an error. These include:
Other debugging aids
|
|
APLX Help : Help on APL language : Errors : Overview of error handling and the State Indicator
|
Copyright © 1996-2010 MicroAPL Ltd