changed try-catch for if.