Handle exception correctly in unit-test