What is happening here? OnError with Pause

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

What is happening here? OnError with Pause

07 Sep 2021, 11:42

I'd be interested on hearing opinions on a code that is behaving a bit weird:

Code: Select all

OnError(ErrorHandler)

ErrorHandler(Thrown, Mode) {
   return Pause()
}

F1:: {
   Throw
}
What happens is that the script pauses (red tray icon), throws the error (dialog message) and then resumes again (green icon) by itself.
It doesn't happen without the return. But it was a fat arrow function when I found it.
User avatar
boiler
Posts: 17197
Joined: 21 Dec 2014, 02:44

Re: What is happening here? OnError with Pause

07 Sep 2021, 13:03

It seems to me that it pauses the current thread, but it resumes because the current thread is ended when you return from it.
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: What is happening here? OnError with Pause

07 Sep 2021, 13:38

That seems to make some sense. I was thinking in pausing the script, but as you say Pause() acts on the thread.

After other attempts what I've seen puting a timer is that the timer doesn't go back to work even if the icon turns to green.
But curiously using Pause(1) the icon stays red.

Edit: Reworded a bit.
User avatar
boiler
Posts: 17197
Joined: 21 Dec 2014, 02:44

Re: What is happening here? OnError with Pause

07 Sep 2021, 14:00

safetycar wrote: What I saw puting a timer is that the timer doesn't go back to work even if the icon turns to green.
But curiously using Pause(1) the icon stays red.
That is because the icon indicates that status of the current thread (the script’s main thread or other thread), which is not paused.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: What is happening here? OnError with Pause

07 Sep 2021, 14:03

the "current thread" is the one that the OnError callback is executing in. if it pauses the current thread, why is the current thread returning from? it should have been paused, right... so it makes no sense. it only makes sense that this is a bug
the code should have behaved identically to:

Code: Select all

ErrorHandler(Thrown, Mode) {
   Pause()
   return
}
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: What is happening here? OnError with Pause

07 Sep 2021, 14:06

boiler wrote:
07 Sep 2021, 14:00
That is because the icon indicates that status of the current thread (the script’s main thread or other thread), which is not paused.
But this two scripts act the same with the timer.

But this leaves the icon green:

Code: Select all

OnError((*)=>(Pause()))
SetTimer(()=>Tooltip("Timer"), 100)
F1::Throw
And this leaves it red:

Code: Select all

OnError((*)=>(Pause(1)))
SetTimer(()=>Tooltip("Timer"), 100)
F1::Throw
Both of them keep the timer stopped. The only difference is the "1".

Edit: I reported it as possible bug here: viewtopic.php?f=14&t=94664

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Giresharu, Hiroki-H, songdg and 68 guests