These operators are extended from the IEC 61131-3 standard and they are used for specific exception handling in IEC code.
Syntax
__TRY
<statements_try>
__CATCH(exec)
<statements_catch>
__FINALLY
<statements_finally>
__ENDTRY
<statements_next>
When a statement in the __Try operator throws an exception, the application does not stop. Instead, it executes
the statements below __Catch and therefore starts the exception handling. Then it executes the instructions below
__FINALLY . The exception handling ends with __ENDTRY. Then the application executes the next statements.
An IEC variable for an exception has the data type __System.ExceptionCode.
Example
If the statement in __TRY throws an exception, then program execution is not stopped. Instead, the statement
in __CATCH is executed. Therefore, in this example the exc function is executed and then the statement below __FINALLY. Then it executes the instructions below __FINALLY.
FUNCTION Tester : UDINT
VAR_INPUT
count : UDINT;
END_VAR
VAR_OUTPUT
strExceptionText : STRING;
END_VAR
VAR
exc : __SYSTEM.ExceptionCode;
END_VAR
__TRY
Tester := tryFun(count := count, testcase := g_testcase); //Diese Anweisung wird getestet. Wenn sie eine Exception produziert, werden zuerst die Anweisung unter __CATCH und danach die Anweisung unter __FINALLY ausgeführt.
__CATCH(exc)
HandleException(exc, strExceptionText => strExceptionText);
__FINALLY
GVL.g_count := GVL.g_count + 2;
__ENDTRY
For more information, see: ⮫ “Command: Stop Execution on Handled Exceptions ”
-
Data Type '__System.ExceptionCode'