In contrast to the shareholder, the loan holder is not a co-owner of the company. He is a creditor and the loaned money is outside capital. If the company has to file for bankruptcy, the loan holders are paid off even before the shareholders.
When a state goes bankrupt, it does not look very good for the yield for the government bonds. The state then is officially insolvent and does not pay it's debts back. A violent change of government can also lead to the new government's refusal to service the old regime's debts. Some countries such as Greece are over indebted to such a degree that the state would actually have to declare bankruptcy. National bankruptcies have only rarely been observed in history, in many cases the following governments decided to settle the debts at some point.
But industrial nations in particular are said to be politically and economically stable. Therefore government as well as corporate bonds are said to be less risky than shares.
Besides the issuer's risk, loans have further classifications of risks of the same issuer, as e.g. the different Tier 1 levels. Subordinate additional Tier-1-loans are only serviced after other loan debts are paid back. Besides there are further categories of „Senior Bonds“ which are, for example, additionally collateralized by real estate and other values.
At this time (in 2017) we probably are in the midst of a loan bubble. Government bonds have negative interest. Corporate bonds of low quality (so called junk bonds) do pay good interest, as the „Scholz Bond“ with 8.5%, but the ability of the creditors to pay back is not fully guaranteed.