close window before prompting error message