Added try/catch around localStorage calls