add try/catch on window.load and window.closing