IgnoreErrors doesn't seem to work in Error Handler

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
jackdleach
Newbie
Posts: 5
Joined: Mon Jan 26, 2015 5:38 am

IgnoreErrors doesn't seem to work in Error Handler

Post by jackdleach » Wed Feb 11, 2015 4:13 am

Hello,

I have an error handler set up that attempts to close the window and elegantly back out of the script. On occasion, the window it's attempting to close can't be found, and it enters a loop in outputting to the error log.

Here's the pertinent script pieces:

Code: Select all

// first two executable lines:
Let>IGNOREERRORS=0
Let>ONERROR=errorHandler

// script body here

SRT>errorHandler
    Let>IGNOREERRORS=1                                      // note ignore errors
    Let>ErrMsg=LAST_ERROR_LINE
    ConCat>ErrMsg,": "
    ConCat>ErrMsg,LAST_ERROR
    Timestamp>%SCRIPT_DIR%\error.log,ErrMsg
    CloseWindow>windowTitle                                     // line 363
    Wait>5
    Exit>0
END>errorHandler
The error log has about 16k entries over a 5 minute time span (the script is set to run every 5 minutes for testing): presumably an infinite loop if not killed by starting a new task(?).

Code: Select all

14:03:50:616 - 363": "Specified Window "[windowname]" Not Present.
Any Subsequent Key Sends In Script May Cause Exceptions.
14:03:50:834 - 363": "Specified Window "[windowname]" Not Present.
Any Subsequent Key Sends In Script May Cause Exceptions.
.. etc etc

I would have expected the IGNOREERRORS=1 statement at the start of the error handler to ignore that error from CloseWindow and just continue trying to exit the script instead of recursing itself.

Any ideas on how I can stop this behavior? I can try moving the CloseWindow command to it's own SRT and put the IGNOREERRORS in there, but I'm curious if there's some known issue with this in a handler or if I'm missing something obvious?

Thanks,
-jack

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

Re: IgnoreErrors doesn't seem to work in Error Handler

Post by Marcus Tettmar » Wed Feb 11, 2015 2:02 pm

The problem here is that you get stuck in a never ending loop - your error will cause the error handler to fire, and you're already in the error handler. So you get stuck.

You can get round this by also setting ONERROR to an empty subroutine. Try stepping through this example:

Code: Select all

Let>ONERROR=MyErrs

Let>a=1
//force an error
Let>a=a/0


SRT>MyErrs
  Msg>LAST_ERROR
  
  //Ignore errors here ...
  Let>ONERROR=donothing
  Let>IGNOREERRORS=1

  //force an error to test  
  Let>a=a/0

  //Revert back to my error handler .. 
  Let>IGNOREERRORS=0
  Let>ONERROR=MyErrs
END>MyErrs

SRT>donothing
  //dummy error handler when we want to do nothing and ignore
END>donothing
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

jackdleach
Newbie
Posts: 5
Joined: Mon Jan 26, 2015 5:38 am

Re: IgnoreErrors doesn't seem to work in Error Handler

Post by jackdleach » Wed Feb 11, 2015 2:46 pm

Ah, I see... I thought that's what IGNOREERRORS was for, didn't realize I need to reset the handler itself as well.

I'll try it next time I'm playing around in there. Thanks

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