using exceptions handling for astype fucntion