Handle exceptions in __toString to avoid errors