Added try...catch to the event handler