Added error handler to avoid termination on error (which occurs whenever a focused window is closed)