Replaced broad exception with ValueError