Upon appearing or being brought before the judge or referee, the judgment debtor, or officer required to answer for a corporation, may be examined under oath, and witnesses may be required to appear and testify on behalf of either party, and the debtor may be represented by counsel; and no person, on such examination, shall be excused from answering any question on the ground that the examination will tend to convict the person of the commission of a fraud, but an answer shall not be used as evidence against the person in any criminal proceeding. If the examination is before a referee, the referee shall certify the testimony and proceedings to the judge.