Added try-catch block in window procedures