EcoStruxure Machine Expert version 1.1 does not support the M258, LMC058 and LMC078 controllers.

__TRY, __CATCH, __FINALLY, __ENDTRY

Definition

These operators are not specified by the IEC 61131-3 standard.

The __TRY, __CATCH, __FINALLY, __ENDTRY operators are used for specific handling of exceptions in IEC code. With these operators, you can execute specific statements in case an error is detected. Furthermore, the program is not stopped (as usual) when an exception is detected.

Syntax

__TRY
<statements_try>
__CATCH(exec)
<statements_catch>
__FINALLY
<statements_finally>
__ENDTRY
<statements_next>

Function

If an exception is detected while <statements_try> is executed (even in functions called from there), then <statements_catch> is executed. In that way, execution does not stop as it is the case when other exceptions are detected. However, there is a log message in the runtime system with information about the range offset and the type of exception that has been detected.

After executing <statements_catch>, <statements_finally> is automatically executed (if programmed), and then <statements_next> is executed.

The variable <exception> must be of type __SystemExceptionCode.

Example

If the statement in __TRY produces an exception, then program execution is not stopped, and then the statements in __CATCH are executed. This means that the function exc is executed. Then the statement in __ENDTRY is executed.

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);
//This statement is tested. If it produces an exception, then the statement in __CATCH is executed first, and then the statement in __FINALLY.
__CATCH(exc)
HandleException(exc, strExceptionText => strExceptionText);
__FINALLY
GVL.g_count := GVL.g_count + 2;
__ENDTRY

Use the Stop execution on handled exceptions command to stop execution at the error location despite the programmed exception handling.

Type __System.Exception

TYPE ExceptionCode: 
( RTSEXCPT_UNKNOWN                              := 16#FFFFFFFF,
RTSEXCPT_NOEXCEPTION                            := 16#00000000,
RTSEXCPT_WATCHDOG                               := 16#00000010,
RTSEXCPT_HARDWAREWATCHDOG                       := 16#00000011,
RTSEXCPT_IO_CONFIG_ERROR                        := 16#00000012,
RTSEXCPT_PROGRAMCHECKSUM                        := 16#00000013,
RTSEXCPT_FIELDBUS_ERROR                         := 16#00000014,
RTSEXCPT_IOUPDATE_ERROR                         := 16#00000015,
RTSEXCPT_CYCLE_TIME_EXCEED                      := 16#00000016,
RTSEXCPT_ONLCHANGE_PROGRAM_EXCEEDED             := 16#00000017,
RTSEXCPT_UNRESOLVED_EXTREFS                     := 16#00000018,
RTSEXCPT_DOWNLOAD_REJECTED                      := 16#00000019,
RTSEXCPT_BOOTPROJECT_REJECTED_DUE_RETAIN_ERROR  := 16#0000001A,
RTSEXCPT_LOADBOOTPROJECT_FAILED                 := 16#0000001B,
RTSEXCPT_OUT_OF_MEMORY                          := 16#0000001C,
RTSEXCPT_RETAIN_MEMORY_ERROR                    := 16#0000001D,
RTSEXCPT_BOOTPROJECT_CRASH                      := 16#0000001E,
RTSEXCPT_BOOTPROJECTTARGETMISMATCH              := 16#00000021,
RTSEXCPT_SCHEDULEERROR                          := 16#00000022,
RTSEXCPT_FILE_CHECKSUM_ERR                      := 16#00000023,
RTSEXCPT_RETAIN_IDENTITY_MISMATCH               := 16#00000024,
RTSEXCPT_IEC_TASK_CONFIG_ERROR                  := 16#00000025,
RTSEXCPT_APP_TARGET_MISMATCH                    := 16#00000026,
RTSEXCPT_ILLEGAL_INSTRUCTION                    := 16#00000050,
RTSEXCPT_ACCESS_VIOLATION                       := 16#00000051,
RTSEXCPT_PRIV_INSTRUCTION                       := 16#00000052,
RTSEXCPT_IN_PAGE_ERROR                          := 16#00000053,
RTSEXCPT_STACK_OVERFLOW                         := 16#00000054,
RTSEXCPT_INVALID_DISPOSITION                    := 16#00000055,
RTSEXCPT_INVALID_HANDLE                         := 16#00000056,
RTSEXCPT_GUARD_PAGE                             := 16#00000057,
RTSEXCPT_DOUBLE_FAULT                           := 16#00000058,
RTSEXCPT_INVALID_OPCODE                         := 16#00000059,
RTSEXCPT_MISALIGNMENT                           := 16#00000100,
RTSEXCPT_ARRAYBOUNDS                            := 16#00000101,
RTSEXCPT_DIVIDEBYZERO                           := 16#00000102,
RTSEXCPT_OVERFLOW                               := 16#00000103,
RTSEXCPT_NONCONTINUABLE                         := 16#00000104,
RTSEXCPT_PROCESSORLOAD_WATCHDOG                 := 16#00000105,
RTSEXCPT_FPU_ERROR                              := 16#00000150,
RTSEXCPT_FPU_DENORMAL_OPERAND                   := 16#00000151,
RTSEXCPT_FPU_DIVIDEBYZERO                       := 16#00000152,
RTSEXCPT_FPU_INEXACT_RESULT                     := 16#00000153,
RTSEXCPT_FPU_INVALID_OPERATION                  := 16#00000154,
RTSEXCPT_FPU_OVERFLOW                           := 16#00000155,
RTSEXCPT_FPU_STACK_CHECK                        := 16#00000156,
RTSEXCPT_FPU_UNDERFLOW                          := 16#00000157,
RTSEXCPT_VENDOR_EXCEPTION_BASE                  := 16#00002000
RTSEXCPT_USER_EXCEPTION_BASE                    :=16#00010000 )
UDINT ; END_TYPE