Fixed a small logic bug when raising exception