Suppress error message

Hi. I have created a snippet (latest in Show and Tell ). The Shifted section has an {error} function to pick up a blank space in the num variable but it also throws up another error. Is there a way to suppress this error message.

Hi Tony,

Can you be more specific about the error you are seeing? If you could copy the specific part here, that would be helpful.

In general, you can use the catch() function to "catch" an error and return a different result. If catch's first argument is an error, it returns the second argument; otherwise, it returns the first.

Catch() returns the first argument when it is not an error {=catch(1+2, "Oops an error happened!")}

Catch() returns the second argument when the first is an error {=catch(1+"banana", "Oops an error happened!")}

Shifted
You can adjust the number, period (D,W,M,Y) and Start From Date

num
Please enter a number
W

14/03/2026
Invalid time shift "+W"; the proper form is "[length][unit]" like "2D" or "1Y".

{error: Please enter a number; block=yes; type=info}{endif}{formmenu: D; default=W; M; Y; name=period; cols=5}{formdate: YYYY-MM-DD; name=start_date; cols=15}{endnote}{time: Do MMMM YYYY; at={=start_date}; shift=+{=num}{=period}}
{endif}

If you look at the Shifted option and blank the number I get two errors, one I set up plus a system one. I understand why the error occurs, just wonder if I can suppress it

I think the key question is what should happen when they insert an invalid value for the weeks number, generally I think an error makes sense.

If you don't want an error, and you want it to fall back to something else (like a shift of 0 weeks), you can check if the value they entered is a number and default to 0 if it is not. I would be careful about doing this, though, as it may lead to unexpected outputs for the user if they didn't realize what they entered was invalid.

Here is an example:

Shift weeks: {formtext: name=shift; default=1} {if: not isNumber(shift)}{error: Defaulting to 0!}{endif}
{time: LL; shift=+{=shift if isNumber(shift) else 0}W}

1 Like

I agree. I’ll leave it as it is. Thanks for looking at it. Tony