David J Murray Dev
~ Learn and Do - Excel and Share ~

Try and Catch

Aug 1, 2007

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.

I have always liked the try/catch control structures available in a number of other structured languages like javascript and python and even java.

JavaScript has the try/catch/finally and Python has the try/except/finally syntax.

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
  • Description
  • 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.

About the Author

<a href="https://davidjmurray.dev/losucag/davidjmurray/" target="_self">djm</a>


I have been in the computer/IT industry for over 35 years. After spending half a life-time in highly proprietary database environments, I have succumbed to the WordPress Eco-system and I'm well down the chasm. I am specializing in AWS hosting, Wordpress CMS, Elegant Themes, in particular Divi and Extra themes.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This