If the jury is discharged because the facts as charged do not constitute an offense punishable by law, the court must order that the defendant, if in custody, be discharged; or if admitted to bail, that his bail be exonerated; or, if he has deposited money or if money has been deposited by another or others instead of bail for his appearance, that the money be refunded to him or to the person or persons found by the court to have deposited said money on behalf of said defendant, unless in its opinion a new indictment or information can be framed upon which the defendant can be legally convicted, in which case it may direct the district attorney to file a new information, or (if the defendant has not been committed by a magistrate) direct that the case be submitted to the same or another grand jury; and the same proceedings must be had thereon as are prescribed in section 998; provided, that after such order or submission the defendant may be examined before a magistrate, and discharged or committed by him as in other cases.
Ca. Pen. Code § 1117