Replace [0-9]+ checks by try-catch.