Print error msg before raising exception on error