There is a hierarchy of which creditors and investors will be serviced first in the event that a company goes bankrupt. When a company goes bankrupt, it is unable to pay back the money that it borrowed. The higher the bond's rating, the less likely that the issuer will go bankrupt.
To learn more about bond ratings, see “What are Bond Ratings?”
The possibility of bankruptcy is the risk associated with investing in bonds - you can never know for sure if you will get your money back. Typically, bonds with higher coupons are riskier investments (again, the recurring theme of higher returns = higher risks!). For example, if you see a bond with a 30% coupon, there is (obviously) a greatly increased chance that the company will not be able to pay back your loan.
However, as a bond holder, you will have what’s called a “senior claim” on the residual assets of the bankrupt company. Senior securities receive service first in such situations. When the bankruptcy judge distributes these assets, they first go to the bondholders, and only then, to the common shareholders.
Therefore, in most cases, bond holders might get a percentage of their money back (of course, not everything), but a common shareholder may never get any money back.
What is Bankruptcy Court?
How Can I Check if My Portfolio is Diversified?