Custom error handling

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ForrrestMaster
Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:42 pm

Custom error handling

Post by ForrrestMaster » Thu Sep 15, 2016 12:10 am

Hello,

So I have been trying to make my own error handling based on a waitscreenimage timeout.

Under each WaitScreenImage, I have

Code: Select all

if>WSI_TIMEDOUT=TRUE
GoSub>failed
Endif
It will execute the "failed" subroutine, but then it will jump to the step where it last was prior to the timeout. I would like for it to jump to a label set at the very beginning, essentially restarting the script. I have tried using SkipLabel to point it back to the very top, but its not working. Using GoTo in a subroutine causes that warning popup and halts script execution. Anyway to accomplish this?


Here is the jist of my script. It uses multiple logins from a text file.

Code: Select all

GoSub>getinfo
Label>startover
GoSub>login

SRT>getinfo
gets info from a txt file
END>getinfo

SRT>login
uses images to wait to input information
waitimage timeout happens here
some other lines of scripting
END>login

SRT>failed
restarts the application from the very beginning
SkipLabel>startover
END>failed

Goto>startover

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

Re: Custom error handling

Post by Marcus Tettmar » Thu Sep 15, 2016 9:21 am

Hi,

The label you jump to needs to be later in the script (after the place the subroutine is called). So you would need to do something like this:

Code: Select all

Label>start
Let>WW_TIMEOUT=20

WaitWindowOpen>nowindow
GoSub>CheckWindowTimeout

SRT>CheckWindowTimeout
  If>WW_RESULT=FALSE
    SkipLabel>restart
  Endif
END>CheckWindowTimeout


//normal end
Exit>0

//we get here if a subroutine jumps here
Label>restart
Goto>start
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ForrrestMaster
Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:42 pm

Re: Custom error handling

Post by ForrrestMaster » Thu Sep 15, 2016 8:15 pm

Thank you for your reply.

Code: Select all

SRT>failed
FindImagePos>C:\Users\Chase\Documents\Macro Scheduler 14\TestCase\image_44.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif
SkipLabel>letsrestart
END>failed
label>letsrestart
GoTo>startover
Thats what I have at the end of my script, but after debugging it, when it uses skiplabel to jump to lets restart, I still get an error message saying that I shouldnt be jumping to labels while in a subroutine.

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

Re: Custom error handling

Post by Marcus Tettmar » Thu Sep 15, 2016 8:16 pm

Could you be jumping into "failed" from another subroutine?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

ForrrestMaster
Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:42 pm

Re: Custom error handling

Post by ForrrestMaster » Thu Sep 15, 2016 8:25 pm

Yes, I am actually. I think I know what you are saying now.

Have the error check in each previous subroutine skip to a label, then have a GoSub underneath it. Like

Code: Select all

srt>1
thing that caused failure
Skiplabel>itfailed
end>1

srt>2
dsfas
end>2

SRT>failure
error handling
end>failure
label>itfailed
GoSub>failure

ForrrestMaster
Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:42 pm

Re: Custom error handling

Post by ForrrestMaster » Sun Sep 18, 2016 6:42 am

Im still having the issue. I have multiple subroutines with different snipets of code, and all waitforimages time out and go to my failure label. I have tried having the error handling in a SRT and out of a subroutine. Is there a way to disable that warning prompt?

ForrrestMaster
Newbie
Posts: 8
Joined: Fri Sep 02, 2016 7:42 pm

Re: Custom error handling

Post by ForrrestMaster » Sun Sep 18, 2016 6:44 am

Accidental Double post

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Custom error handling

Post by PepsiHog » Sun Sep 18, 2016 9:04 pm

Hi,

Jumping in and out of srt's is a pain. Problem is you can't stop GoSub from returning. Plus there are situations where depending on the srt you gosub to, you may want that srt to jump to yet another. But this causes what I call "the rubberband effect" It springs back to the original srt, and by then things may have changed to the point where it causes an error in the original srt. Or you get that annoying message about jumping out of a srt. Which for the most part I agree and understand the message. But there still are some cases where you wish it would stop warning you.

I have made my own solution to this problem. It is no longer a problem for me. Don't use gosubs in your srt's. LOL! You think I'm NUTS! And I am. Here is how....

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Begin Program

let>MySrt=FirstSRT


let>neverending=0
While>neverending=0
gosub>%MySrt%
endwhile


srt>FirstSRT
blah, blah, blah
does what you need.
if>result=blah
let>MySrt=NextSRT
else
let MySrt=FirstSRT
endif

End>FirstSRT

rest of program.....
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

So all you do is conditionally set the srt you want to call. The current srt will end on it's own and the program will jump back to the neverending loop and gosub to the next srt. Which is whatever srt you assigned to MySrt.

So in other words, don't use gosub in your srt's. This works great when you are writing a macro piece by piece and need to avoid pain-in-the-butt-messages. Later once you figure everything out, you can remove MySrt and make appropriate gosubs according to what you need. Or not.

Ofcourse, you still have to plan out the srt's. When your srt gets called, keep in mind, it will start from the top. There may be times when you want to use gosub if you know the called srt won't be calling any others, or you need it to return.

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

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