0

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
Roald
  • 2,459
  • 16
  • 43
  • Adding this Q&A because Google doesn't show any results when searching for the error code. – Roald Mar 04 '20 at 08:03

1 Answers1

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.

Roald
  • 2,459
  • 16
  • 43