Handling str2date() Error

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

pfield
Posts: 20
Joined: Thu Mar 19, 2020 3:46 pm

Handling str2date() Error

Postby pfield » Thu Mar 26, 2020 7:54 pm

Hi,

I would like to trap str2date() errors in my CTL code, however, for cases where the incoming format is unexpected then the whole graph assembly fails. I was hoping the transformOnError() function would handle this so I could perform some action (e.g. SKIP or write to a separate output port) but the whole job just terminates.

How can i trap this sort of error and introduce some sort of handling?

Thanks,
Paul

dpavlis
Posts: 189
Joined: Sat Mar 10, 2007 8:12 pm

Re: Handling str2date() Error

Postby dpavlis » Tue Mar 31, 2020 2:52 pm

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.)

Code: Select all

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

Code: Select all

date mydate;
mydate = str2date(....params...) : 2000-01-01;  //notice the ":" operator
David Pavlis
CloverCARE Support
CloverDX | Rapid Data Integration

Visit us online at http://www.cloverdx.com

pfield
Posts: 20
Joined: Thu Mar 19, 2020 3:46 pm

Re: Handling str2date() Error

Postby pfield » Wed Apr 01, 2020 12:22 am

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

dpavlis
Posts: 189
Joined: Sat Mar 10, 2007 8:12 pm

Re: Handling str2date() Error

Postby dpavlis » Wed Apr 01, 2020 12:26 pm

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.
David Pavlis
CloverCARE Support
CloverDX | Rapid Data Integration

Visit us online at http://www.cloverdx.com


cron