Uses try/except to catch ValueError

Signed-off-by: Martin Koistinen <mkoistinen@gmail.com>