Section 2. If a discontinuance or a nonsuit is entered in an action solely in consequence of an answer of the defendant which alleges his discharge in bankruptcy or insolvency, the defendant shall recover no costs. If issue is joined upon such defence solely and judgment is rendered for the defendant, he shall recover only his costs accruing after the joinder of such issue.