为什么 try catch 语句在 TwinCAT 4024.7 中不起作用 [英] Why dont the try catch statements work in TwinCAT 4024.7
问题描述
我正在尝试自 TwinCAT 4024.0 以来可用的新实现的 try/catch 语句.但是,编译时出现以下错误:
I'm trying the newly implemented try/catch statements which are available since TwinCAT 4024.0. However, I'm getting the following error when compiling:
当前设备的代码生成器不支持结构化异常处理.
The codegenerator for the current device does not support structured exception handling.
示例代码(来源):
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 语句.这也在 中提到这篇文章.
Turns out the try catch statements are not supported for 64-bit systems yet. This is also mentioned in this article.
来自这篇文章的评论部分,关于为什么它还不能在 64 位上运行:
From the comment section of this article on why it doesn't work on 64-bit yet:
在出现异常的情况下,内部会发生很多事情.为了例如,必须清理堆栈.尤其是嵌套很深的方法调用,这可能意味着很多工作.我怀疑记忆管理在 32 位下的结构与在 64 位下不同.但是,我假设这将在 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.
这篇关于为什么 try catch 语句在 TwinCAT 4024.7 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!