catch command

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf catch command

  • Creator
    Topic
  • #49883
    Michael Hertel
    Participant

      What am I doing wrong?

      I’m under the impression that err is valued only if something blows up.

      catch {something blew up} err

      What I’m trying to do is look for a bad or missing date so I thought that:

      set txa4 {}

      set err {}

      catch {set data [clock scan $txa4]} err

      err would be valued only if the date was missing or invalid and the scan command would blow up. But when I check $err, it seems to be valued with something.

    Viewing 1 reply thread
    • Author
      Replies
      • #63999
        Rob Abbott
        Keymaster

          Hi Mike

          catch will return 1 if error, 0 if no error

          err will be set to either the error or the return value of the statements inside braces.

          It’s best to avoid using “set” inside a catch.  I would revise your code like this

          if [catch {clock scan $txa4} data] {

            # an error occurred – data contains the error

          } else {

            # no error occurred – data contains the result of clock scan

          }

          Rob Abbott
          Cloverleaf Emeritus

        • #64000
          Michael Hertel
          Participant

            Thanks Rob!

        Viewing 1 reply thread
        • The forum ‘Cloverleaf’ is closed to new topics and replies.