Page 1 of 1

What is happening here? OnError with Pause

Posted: 07 Sep 2021, 11:42
by safetycar
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.

Re: What is happening here? OnError with Pause

Posted: 07 Sep 2021, 13:03
by boiler
It seems to me that it pauses the current thread, but it resumes because the current thread is ended when you return from it.

Re: What is happening here? OnError with Pause

Posted: 07 Sep 2021, 13:38
by safetycar
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.

Re: What is happening here? OnError with Pause

Posted: 07 Sep 2021, 14:00
by boiler
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.

Re: What is happening here? OnError with Pause

Posted: 07 Sep 2021, 14:03
by swagfag
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
}

Re: What is happening here? OnError with Pause

Posted: 07 Sep 2021, 14:06
by safetycar
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