The use of THEN/ELSE came up in the U2 lists. I have always had trouble with these statements as they introduce significant overheads around a simple statement like the OPEN or OCONV.
As UniBasic does not have this construct, I started thinking about how easy it would be to implement something within U2.
There are three different levels where this construct could be created and used.
- UniBasic via a pre-compiler
- SB+ Paragraph process statement which is converted/compiled into a bunch of IF/THEN/ELSE/GOTO’s
- SB+ new process that is a merge of the Conditional and Shell Wrapper Processes
As all SB+ processes return an error status, it seems a logic place to start attempting to implement this control structure in SB+.
By creating a new file (TRYCATCH.DEFN for instance) with fields and a screen to capture the control structure, a program could convert the try/catch definition into a SB+ Paragraph.
Starting with a screen layout for the user to enter such a process:
- Process Name
- Try Statements
- Catch Statements
- Else Statement
- Finally Statements
It would be easier to make the Try Statements a list of existing SB+ processes. The Catch would be similar to a CASE statement selected by the error return (RTN.FLAG) which selects a SB+ process to run. The Else is actually a CASE 1. The Finally statement would also be a single SB+ process to run.
The end result would be a SB+ Paragraph which is automatically created from the supplied information. And yes, it would have a bunch of GOTO’s.