为什么 try catch 语句在 TwinCAT 4024.7 中不起作用
Why dont the try catch statements work in TwinCAT 4024.7
我正在尝试自 TwinCAT 4024.0 以来可用的新实现的 try/catch 语句。但是,编译时出现以下错误:
The codegenerator for the current device does not support structured exception handling.
示例代码 (source):
FUNCTION F_Calc : LREAL
VAR_INPUT
pData : POINTER TO ARRAY [0..9] OF LREAL;
nElementA : INT;
nElementB : INT;
END_VAR
VAR
exc : __SYSTEM.ExceptionCode;
END_VAR
__TRY
F_Calc := pData^[nElementA] / pData^[nElementB];
__CATCH (exc)
IF (exc = __SYSTEM.ExceptionCode.RTSEXCPT_ARRAYBOUNDS) THEN
F_Calc := -1;
ELSIF ((exc = __SYSTEM.ExceptionCode.RTSEXCPT_FPU_DIVIDEBYZERO) OR
(exc = __SYSTEM.ExceptionCode.RTSEXCPT_DIVIDEBYZERO)) THEN
F_Calc := -2;
ELSIF (exc = __SYSTEM.ExceptionCode.RTSEXCPT_ACCESS_VIOLATION) THEN
F_Calc := -3;
ELSE
F_Calc := -4;
END_IF
__ENDTRY
事实证明,64 位系统尚不支持 try catch 语句。 this 文章中也提到了这一点。
来自本文关于为什么它不能在 64 位上运行的评论部分:
In the case of an exception, quite a lot happens internally. For
example, the stack must be cleaned. Especially with deeply nested
method calls, this can mean a lot of work. I suspect that memory
management is structured under 32 bit differently than under 64 bits.
However, I assume that this will be implemented for 64 bit systems in
a later build.
我正在尝试自 TwinCAT 4024.0 以来可用的新实现的 try/catch 语句。但是,编译时出现以下错误:
The codegenerator for the current device does not support structured exception handling.
示例代码 (source):
FUNCTION F_Calc : LREAL
VAR_INPUT
pData : POINTER TO ARRAY [0..9] OF LREAL;
nElementA : INT;
nElementB : INT;
END_VAR
VAR
exc : __SYSTEM.ExceptionCode;
END_VAR
__TRY
F_Calc := pData^[nElementA] / pData^[nElementB];
__CATCH (exc)
IF (exc = __SYSTEM.ExceptionCode.RTSEXCPT_ARRAYBOUNDS) THEN
F_Calc := -1;
ELSIF ((exc = __SYSTEM.ExceptionCode.RTSEXCPT_FPU_DIVIDEBYZERO) OR
(exc = __SYSTEM.ExceptionCode.RTSEXCPT_DIVIDEBYZERO)) THEN
F_Calc := -2;
ELSIF (exc = __SYSTEM.ExceptionCode.RTSEXCPT_ACCESS_VIOLATION) THEN
F_Calc := -3;
ELSE
F_Calc := -4;
END_IF
__ENDTRY
事实证明,64 位系统尚不支持 try catch 语句。 this 文章中也提到了这一点。
来自本文关于为什么它不能在 64 位上运行的评论部分:
In the case of an exception, quite a lot happens internally. For example, the stack must be cleaned. Especially with deeply nested method calls, this can mean a lot of work. I suspect that memory management is structured under 32 bit differently than under 64 bits. However, I assume that this will be implemented for 64 bit systems in a later build.