Correcting javascript exception