Add error handling to main window