The Statement Block
A statement block contains the main list of statements that are normally executed in sequence. Each statement block may also contain an error handling section that will be executed if there is an error in the main list.
stmtblock ::= [ stmtlist ] [ OnError [ stmtlist ] ]
stmtlist ::= [[ statement ]]
A stmtlist contains zero or more individual statements. Most statements can go in any list but there are a few restrictions which will be covered when dealing with those specific statements.
In a finished program there will no point in having an empty statement list, but during development it will be common to have the skeleton of the code with empty lists.
The body of a user defined routine will contain one statement block and various compound statements may have one or more statement blocks within them.
A statement block does not have specific tokens to mark the start and end. These are determined by the syntax of the construct in which it is embedded. For example the top level statement block of a routine is delimited by the Begin and End keywords but in a simple If statement it is delimited by the Then and EndIf keywords.
Rectangle(100, 100) => { 50, 50 }; Circle(100 / n) => { 100, 100 }; LineTo( { 100, 100 } ); OnError Output "Error in main program", Status;
Error Handling
Normally the above example would draw a Rectangle, a Circle and a LineTo. If, however, the value of 'n' was zero there would be a 'division by zero' error. This would cause a jump to the error point while the parameter for the Circle call is being evaluated. So the circle and the line would not be drawn.
If there is no error trap in the block or the surrounding blocks within the routine in which the error occurred the error will be passed up to the calling routine and would appear as an error in the call to the routine - and so on up the call chain until it is trapped.
Once an error has been trapped execution carries on as normal from the statement after the one in which the error occurred.
If there was no error trap in the block, or any surrounding block, then the system itself would receive the error, in which case the drawing of the whole output image would be suppressed.