Why dont the try catch statements work in TwinCAT 4024.7

余生颓废 提交于 2021-01-29 08:40:29

问题


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.

Example code (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

回答1:


Turns out the try catch statements are not supported for 64-bit systems yet. This is also mentioned in this article.

From the comment section of this article on why it doesn't work on 64-bit yet:

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.



来源:https://stackoverflow.com/questions/60521446/why-dont-the-try-catch-statements-work-in-twincat-4024-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!