Add error code handling in exception assert