For projects with big budgets, fixing the bugs and the maintenance can be included in the price since you can add more time for you and your team for the "testing phase."
But often you can get stuck doing smaller budget projects, or get rushed finishing the project, or the client asked for so many revisions that there is actually no time left for this; that testing phase cannot be done properly.
One thing that can be done when this happens (or before in fact) is to give that responsibility to your client; if you are rushed to finish a project or cannot be paid to put the time required to test your code properly, he should do the tests, and then tell you what's wrong. You can give your client a certain period of time to do this; then everything after this period will be charged at hourly rate. Of course if it's a minor bug or something created by obvious negligence, you should probably simply fix it.
That's a fair option you can offer to your client and you can offer this when signing the contract. Think of it as an extended guarantee; as you said software often have bugs but they are also built over a long period of time before being released, and with a team reviewing each others' work. There's also many version of it; your client bought a 1.1 version in a way if he had a small budget or little time to give you to develop the app.
You can include some maintenance for an extra fee, and there's probably other benefits or extra services you can add to that maintenance other than fixing bugs. Another option is to guarantee them a lower hourly rate for 6-12 months to fix bugs or for maintenance if they decide to simply go with the "1.1" version low budget option. This way they won't be scared to be stuck with an app that doesn't work properly and will probably prefer to test it themselves to save a few dollars. The way you can also present it is to tell them "if they ever want to tweak something or add new features, it will be at a lower rate." Otherwise, you can offer as second option a certain amount of hours included in the price for these things and lower that hourly rate a little bit.
Eg. Your first option without maintenance should have a hourly rate a bit higher than the second option with the maintenance included.
The benefit for you: by doing this, you already introduced honestly the option of fixing bugs and gave them the freedom to choose, you offered maintenance and you also welcomed the client to come back to you for more work.
With these info, you can think of a system that could work for you and that lets you client freely choose what he wants. Next time "bugs" will happen, it will be less difficult for you to decide what to do; you'll also know what's fair for YOU and for your client too. And you'll always get paid one way or another.
Note: I'm not a dev, but I do projects management and that's how I deal with that kind of issue. Maybe you will get better answers from entrepreneurs working directly in software or website development.