11 try-catch, Try-catch -21 – ElmoMC SimplIQ Software Manual User Manual

Page 50

Advertising
background image

SimplIQ

Software Manual

4BThe

SimplIQ

User Programming Language

MAN-SIMSW (Ver. 1.4)

5-21

Global variables can still be used and monitored by the user with external terminals,

such as the Composer Smart Terminal.

5.7.11 Try-Catch

A try-catch block is used to react to an expected fault.

Syntax:
try
statement, …, statement,
catch
statement, …, statement
end

The

SimplIQ

drive stores the status (stack and base pointers) and executes the statements

between the try and the catch. If successful, nothing else happens. If an error occurs, the
status is restored and the

SimplIQ

drive executes the catch block. A failure in the catch block

is treated as an unexpected failure.

The

SimplIQ

drive cannot undo statements that were already executed in the try block before

a failure.

Limitations for using a try-catch block include:
ƒ

It is illegal to use goto and return statements within a try-catch block.

ƒ

A control block within a try-catch block must be closed. For example:
int a;


try

if

(a==1)

catch

end

This example is illegal, because the if control block is not closed inside the try block.

ƒ

A try-catch block within a control block must be closed. For example:
int a;

if (a==1)

try

else

catch

end

end

This example is illegal because the try-catch block is not closed within the if block.

Advertising