For the purpose of surrendering the defendant, the bail, at any time and place before they are finally charged, may personally arrest the defendant, or, by a written authority endorsed on a certified copy of the undertaking, may empower a peace officer to do so. Upon the arrest of the defendant by a peace officer, or upon delivery of the defendant to the peace officer by the bail, or upon the defendant's own surrender, the bail are exonerated if the arrest, delivery, or surrender takes place at a time before judgment. But if the arrest, delivery, or surrender does not take place before judgment, the bail are finally charged on their undertaking, and bound to pay the amount of the judgment.