If any such surety (other than bail), or his committee, heir or personal representative, shall confess judgment or suffer judgment to go against him by default, without giving notice to his principal (if the principal be a resident of this state), or his committee or personal representative, to defend the suit, and after such principal, his committee or personal representative offers to defend the suit, and tenders counter security, approved by the court in which the suit is pending, such principal, or his committee, heirs or representative, may have the benefit of every defense against the motion or suit of such surety or his committee, representative or heirs, against him that he might have had against the creditor. And in all cases in which any principal debtor, or his committee, representative or heirs, knowing of the pendency of any suit against his surety or the committee, heir or personal representative of such surety shall not offer to defend such suit, he shall be precluded from making any defense to the claim of the surety which he might have made against the suit of the creditor.