Replace try-catch with if statement