Preparation of carboxylic acids or their salts, halides or anhydrides from carboxylic acid esters or lactones