Make selectWindow more reliable?

Yes it’s annoying. My plan was to let it run overnight but now I’m stuck as it breaks every minute or so on selectWindow.

I have found some try catch emulation. Will see if I can work around the error manually.