Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Assertion or throw exception

FPawlak
2017-05-04
2017-08-29
  • FPawlak - 2017-05-04

    Hi guys,
    I'm looking for some kind of assertion or exception mechanism. I know __try, __catch, __finally. But i don't know how "throw" an exception when something happened. I have seen in help definition of ExceptionCode type, which contains:

    _ _USER _EXCEPTION _BASE := 16#00010000
    

    So maybe it is possible somehow to throw an exception.

    Do we have some kind of assertion mechanism in order to stop whole application if some requirements are not fulfilled?
    Now I have dummy function to do that:

    FUNCTION assert : BOOL
    VAR_INPUT
    Β  Β stopProgram : BOOL;
    END_VAR
    VAR
    Β  Β tmp : INT := 0;
    END_VAR
    IF stopProgram THEN
    Β  Β tmp := 1 / tmp;
    END_IF
    
     
  • uzuwave - 2017-08-21

    Same question here! Any new findings?

     
  • schaepper - 2017-08-29

    You can do this:

    PROGRAM PLC_PRG
    VAR
    result : INT;
    number5 : INT := 5;
    END_VAR

    result := 5 / (number5-number5);

    It will then "automatically" raise an exception . I had to define a variable because codesys is so unbelievably smart it can detect a division by zero if provided with int literals -.-.

    Ofcourse there was nothing useful in the helpfile about throwing an exception...

     

Log in to post a comment.