core: improve exceptions handling