Customer Portal

Handling str2date() Error

Comments 3

  • Avatar
    dpavlis
    0
    Comment actions Permalink
    Hi Paul,

    There are 2 options, how to handle it. One works only with the newest CloverDX release (5.6), the second even in older versions. But both should be used in interpreted mode of CTL.

    Option 1: try-catch (since CloverDX 5.6.)

    date mydate;
    try{
    mydate = str2date( ... params...);
    .. some other code..
    }catch(CTLException ex){
    .. other logic in case of data/format error.
    }


    Option 2: conditional fail expression
    date mydate;
    mydate = str2date(....params...) : 2000-01-01; //notice the ":" operator
  • Avatar
    pfield
    0
    Comment actions Permalink
    Thanks David! This worked for me.

    Out of interest, what was it about this type of error which meant TransformOnError() or similar wasn't possible?

    Paul
  • Avatar
    dpavlis
    0
    Comment actions Permalink
    Hello Paul,

    Can't really answer that.. would need to see the whole transform() & transformOnError() function you have. In general, onError() is called when exception is raised in transform(). If your transformOnError() returns SKIP (constant), then current record is skipped and processing continues with the next one. If you return ALL, then whatever was already written to $out. is sent out (means can be partially updated output record). Of course, you can abort the whole processing inside transformOnError() if you return negative number or call raiseError() function.

    Hope this explains it a bit.

Please sign in to leave a comment.