问题
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