Try, Catch on CDate

Function Main()
  d = "20/05/2023"
    Try
      console.log("Try CDate(" & d & ")")
      d = CDate(d)
    Catch err
      console.log("!!! Catch Try CDate(d) err:" & err)
    Finally
      console.log("Finally d:" & d)
    End Try
End Function

Am I right in thinking the above code should be caught? I can’t get it to catch when converting a “bad” date, in my case a d/m/yy date with d>12

What‘s wrong with d>12 in a d/m/yy date? d stands for day - so any day between 1 and 31 is valid (if the month is right).
I suspect you mean m>12 - but then your example is wrong.
You‘re using the variable name „d“ for 2 different things it seems - to hold the original date and to hold the day portion of the date.
Thomas

Cdate requires a m/d/y format because… America. If you cdate(d/m/y) it throws errors when d>12. I want to catch that error.

I realise there is a whole lot of data validation I should be doing prior to this but issue is more that the “Try” is not catching.

CDate is a helper function in AppStudio. It looks like this:

function CDate(dt) {
    if (typeof (dt) === 'undefined') {
        return 'undefined';
    }
    if (IsDate(dt)) {
        if (VarType(dt.toString(), 1) === 'date') {
            return FormatDateTime(dt, 2); //date
        }
        if (dt.toString().indexOf(':') > -1) {
            return FormatDateTime(dt, 3); //time
        } else {
            return FormatDateTime(dt, 2); //date
        }
    } else {
        return null;
    }
}

It doesn’t return an error - just null.

FormatDateTime() is also a helper function. You can look at it in the Console - it’s quite a big bigger.