Handle exceptions properly