replaced exception catching with if