[Fixed in 15.0.26] ONERROR not capturing string error

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

[Fixed in 15.0.26] ONERROR not capturing string error

Post by Grovkillen » Mon Dec 18, 2023 8:23 am

I have many times found myself with end user problems that have been related to some string ending up in a numerical calculation. These errors aren't catched by the ONERROR function. See example below, the commended out line will be catched but not the string inside the calculation error.

Code: Select all

Let>ONERROR=PROCESS_ERROR

//DBQuery>dbH,,rset,NumRecs,NumFields,0

Let>VALUE=string
Let>CALCULATE={Round(%VALUE%)}

SRT>PROCESS_ERROR
**BREAKPOINT**
END>PROCESS_ERROR
The problem is that I usually have a bunch of scripts running on other computers and they are reporting any error to the server database silently. But once in a while the popup window with the string error is shown to the end user but they rarely report this back to me and I have no way of knowing this in my data base logging.
Last edited by Grovkillen on Mon Sep 23, 2024 4:35 pm, edited 1 time in total.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: ONERROR not capturing string error

Post by Dorian (MJT support) » Mon Dec 18, 2023 10:24 am

Interesting. Have passed to dev.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ONERROR not capturing string error

Post by Marcus Tettmar » Mon Dec 18, 2023 10:40 am

Hmm. Will look at why the error isn't suppressed. In the mean time you could do this:

Code: Select all

//check is a number
RegEx>^\d+(\.\d+)?$,VALUE,0,matches,nm,0
If>nm>0
  Let>CALCULATE={Round(%VALUE%)}
Else
  // not a number
  Gosub>PROCESS_ERROR
Endif
Or:

Code: Select all

//check is a number
VBEval>IsNumeric("%VALUE%"),isNumber
If>isNumber=True
  Let>CALCULATE={Round(%VALUE%)}
Else
  // not a number
  Gosub>PROCESS_ERROR
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Mon Dec 18, 2023 12:22 pm

Thanks for the feedback.

Currently I'm using the good 'ol:

Code: Select all

Let>TEMP_check=VALUE*0
If>TEMP_check=0
  Let>VALUE_round={Round(%VALUE%)}
Else>
  Gosub>PROCESS_ERROR
Endif>
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Thu Mar 21, 2024 7:27 am

FYI

I have a script that constantly is processing open windows. If I run this script on login I get a non-captured error in the if statment after the LibFunc commands. My solution is to have a TEMP_check that force the variables to either a 1 or a 0. It's working but it would be great to see if you could find why the error isn't captured. This is my full code:

Code: Select all

Let>ONERROR=LOG_ERROR
Let>WIN_USEHANDLE=1
Let>WIN_REGEX=1
Let>HIDDEN_WINDOW_FOUND=false
Let>TIMER_ltc_last_added=0
Let>LIST_OF_ALREADY_PROCESSED_HIDDEN_WINDOWS=
Let>LIST_OF_POTENTIAL_HIDDEN_WINDOWS=
Let>HIDDEN_WINDOW_CMD_PATH=C:\Windows\System32\cmd.exe
LowerCase>HIDDEN_WINDOW_CMD_PATH,HIDDEN_WINDOW_CMD_PATH

OnEvent>CUSTOM,LOOP_TO_CHECK_IF_THERES_ANY_HIDDEN_WINDOWS,HIDDEN_WINDOW_FOUND,RUN_THIS_ONLY_WHEN_HIDDEN_WINDOW_IS_FOUND

Label>start_of_main_loop
Wait>10
Goto>start_of_main_loop

SRT>LOOP_TO_CHECK_IF_THERES_ANY_HIDDEN_WINDOWS
  GetWindowList>ALL_WINDOW_HANDLES_CURRENTLY_OPEN
  Separate>ALL_WINDOW_HANDLES_CURRENTLY_OPEN,CRLF,TEMP_list_open_window_handle
  If>TEMP_list_open_window_handle_count>0
    Let>ltc_k=0
    Repeat>ltc_k
      Let>ltc_k=ltc_k+1
      Let>TEMP_ltc_handle=TEMP_list_open_window_handle_%ltc_k%
      IfNot>TEMP_ltc_handle=
        LibFunc>User32,IsIconic,TEMP_ltc_minimized,TEMP_ltc_handle
        If>TEMP_ltc_minimized<>0
          Let>TEMP_ltc_minimized=1
        Endif>
        Position>TEMP_ltc_handle,LIST_OF_ALREADY_PROCESSED_HIDDEN_WINDOWS,1,TEMP_ltc_check_first
        If>TEMP_ltc_check_first<>0
          Let>TEMP_ltc_check_first=1
        Endif>
        GetWindowProcess>TEMP_ltc_handle,TEMP_ltc_pid,TEMP_ltc_process
        LowerCase>TEMP_ltc_process,TEMP_ltc_process
        If>TEMP_ltc_process<>HIDDEN_WINDOW_CMD_PATH
          Let>TEMP_ltc_process=1
        Else>
          Let>TEMP_ltc_process=0
        Endif>
        Let>TEMP_ltc_check_combined={%TEMP_ltc_minimized%+%TEMP_ltc_check_first%+%TEMP_ltc_process%}
        If>TEMP_ltc_check_combined=0
          GetWindowNames>TEMP_ltc_handle,TEMP_ltc_title,TEMP_ltc_class
          LowerCase>TEMP_ltc_title,TEMP_ltc_title
          Position>HIDDEN_WINDOW_CMD_PATH,TEMP_ltc_title,1,TEMP_ltc_check_1
          Position>{"hidden_window"},TEMP_ltc_title,1,TEMP_ltc_check_2
          Position>{"\\bracke-fs01\it\program\task scheduler\"},TEMP_ltc_title,1,TEMP_ltc_check_3
          Let>TEMP_ltc_check={%TEMP_ltc_check_1%+%TEMP_ltc_check_2%+%TEMP_ltc_check_3%}
          If>TEMP_ltc_check>0
            ConCat>LIST_OF_POTENTIAL_HIDDEN_WINDOWS,%TEMP_ltc_handle%%CRLF%
            Timer>TIMER_ltc_last_added
            Let>HIDDEN_WINDOW_FOUND=true
          Endif>
        Endif>
      Endif>
    Until>ltc_k=TEMP_list_open_window_handle_count
  Endif>
  Timer>TIMER_ltc_now
  Let>TIMER_ltc_check=TIMER_ltc_now-TIMER_ltc_last_added
  If>TIMER_ltc_check>60000
    Let>LIST_OF_ALREADY_PROCESSED_HIDDEN_WINDOWS=
  Endif>
END>LOOP_TO_CHECK_IF_THERES_ANY_HIDDEN_WINDOWS

SRT>RUN_THIS_ONLY_WHEN_HIDDEN_WINDOW_IS_FOUND
  Separate>LIST_OF_POTENTIAL_HIDDEN_WINDOWS,CRLF,TEMP_ltc_potential_window
  Let>LIST_OF_POTENTIAL_HIDDEN_WINDOWS=
  If>TEMP_ltc_potential_window_count>0
    Let>ltchw_k=0
    Repeat>ltchw_k
      Let>ltchw_k=ltchw_k+1
      Let>TEMP_window_handle_to_process_ltc=TEMP_ltc_potential_window_%ltchw_k%
      WindowAction>2,TEMP_window_handle_to_process_ltc
      ConCat>LIST_OF_ALREADY_PROCESSED_HIDDEN_WINDOWS,%TEMP_window_handle_to_process_ltc%%CRLF%
    Until>ltchw_k=TEMP_ltc_potential_window_count
  Endif>
  Let>HIDDEN_WINDOW_FOUND=false
END>RUN_THIS_ONLY_WHEN_HIDDEN_WINDOW_IS_FOUND

SRT>PROCESS_ERROR
**BREAKPOINT**
END>PROCESS_ERROR
This part:

Code: Select all

        LibFunc>User32,IsIconic,TEMP_ltc_minimized,TEMP_ltc_handle
        If>TEMP_ltc_minimized<>0
          Let>TEMP_ltc_minimized=1
        Endif>
        Position>TEMP_ltc_handle,LIST_OF_ALREADY_PROCESSED_HIDDEN_WINDOWS,1,TEMP_ltc_check_first
        If>TEMP_ltc_check_first<>0
          Let>TEMP_ltc_check_first=1
        Endif>
        GetWindowProcess>TEMP_ltc_handle,TEMP_ltc_pid,TEMP_ltc_process
        LowerCase>TEMP_ltc_process,TEMP_ltc_process
        If>TEMP_ltc_process<>HIDDEN_WINDOW_CMD_PATH
          Let>TEMP_ltc_process=1
        Else>
          Let>TEMP_ltc_process=0
        Endif>
        Let>TEMP_ltc_check_combined={%TEMP_ltc_minimized%+%TEMP_ltc_check_first%+%TEMP_ltc_process%}
        If>TEMP_ltc_check_combined=0
Used to be:

Code: Select all

        LibFunc>User32,IsIconic,TEMP_ltc_minimized,TEMP_ltc_handle
        Position>TEMP_ltc_handle,LIST_OF_ALREADY_PROCESSED_HIDDEN_WINDOWS,1,TEMP_ltc_first_check
        GetWindowProcess>TEMP_ltc_handle,TEMP_ltc_pid,TEMP_ltc_process
        LowerCase>TEMP_ltc_process,TEMP_ltc_process
        If>{(%TEMP_ltc_minimized% = 0) AND (%TEMP_ltc_first_check% = 0) AND (%TEMP_ltc_process% = %HIDDEN_WINDOW_CMD_PATH%)}
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ONERROR not capturing string error

Post by Marcus Tettmar » Thu Mar 21, 2024 3:03 pm

Hard to say without debugging but I'm wondering if IsIconic is unable to return anything? Have you checked the value being returned there? Something clearly isn't what you're expecting it to be in the If statement and therefore some kind of type error is occurring? Sorry, hard to say without more info, but if you have a solution anyway, then, well, you have a solution. There may be other solutions, but you have one.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Thu Mar 21, 2024 3:25 pm

Yes it's working this way, only wondering if it would be possible to capture the error instead of the error dialog which is halting the script. But yeah no deal breaker only for information if you every get round to it. 8)
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Thu Sep 12, 2024 5:23 am

Is this something we could have fixed soon?
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ONERROR not capturing string error

Post by Marcus Tettmar » Thu Sep 12, 2024 3:37 pm

I don't think the issue is with If. the issue looks to be that the LibFunc failed and as such the parameter list didn't get constructed. I think the only sensible solution is initialise the variables before calling LibFunc. Then check them after and also check the main return variable of LibFunc.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Thu Sep 12, 2024 7:07 pm

I'm referring to the string error in the curly brackets.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ONERROR not capturing string error

Post by Marcus Tettmar » Fri Sep 13, 2024 10:59 am

So the error is from an undeclared string variable in a complex expression. I would make sure those variables are initialised. However if you set IGNOREERRORS to 1 and set an error handler with ONERROR as you have done then any errors inside a complex expression should jump to your ONERROR handler. IGNOREERRORS needs to be 1 for complex expressions to behave like that.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Fri Sep 13, 2024 11:01 am

This was the error I was initially talking about. That one should be captured right?

Code: Select all

Let>ONERROR=PROCESS_ERROR
Let>VALUE=string
Let>CALCULATE={Round(%VALUE%)}

SRT>PROCESS_ERROR
**BREAKPOINT**
END>PROCESS_ERROR
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ONERROR not capturing string error

Post by Marcus Tettmar » Fri Sep 13, 2024 11:10 am

Sorry, presently complex expression errors can be set to be ignored with LET>IGNOREERRORS=1 but not captured.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ONERROR not capturing string error

Post by Grovkillen » Fri Sep 13, 2024 11:11 am

Aha, then I understand.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: ONERROR not capturing string error

Post by Marcus Tettmar » Fri Sep 13, 2024 12:03 pm

Will look to see if we can improve it so that ONERROR works for complex expressions in If statements
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts