Very true that this can happen but we should always diagnose our problems before we waste time and money on repairs that may not be the problem.I had a mower do this one time, the gas tank had some bugs and rubber from the gas cap, blocking the gas flow to the carb. I removed the tank, cleaned it out and it's been running since.
People with a decent amount of experience with engines can usually tell whether one is a fuel or ignition issue when it dies. Ignition is usually abruptly like you turn the key off or sometimes we'll have a few crisp stutters or pops but it will be different than fuel starvation issue where it will more slowly lose power and get weak before it shuts off.
For the past 10 years or so, maybe longer, most of the problems are fuel related for whatever reason.
Could be gas tank, fuel lines, blockages, carburetor solenoids, debris and floating stuff in the carburetor, restricted Jets etc but it's far more common than ignition.
The go-to even today is still to try a new spark plug which is just a waste of time 95 plus percent of the time.
The most efficient way to start a diagnosis is to give it an external fuel source or more fuel.
You will often find that when one starts to mess up if you add choke quickly maybe not full choke but half to three quarter choke but some type of choke amount that if it starts to smooth out for at least a couple of seconds then you can guarantee it's a fuel issue.
Then you can do things like the easiest first of popping the fuel line off the carburetor to see if you have good flow sometimes having to crank it if you have a fuel pump or pulsator pump.
Then you can remove the fuel solenoid on the bottom of the carb and simply hold your finger on it if you have to to see if that solves the problem because it does a decent percentage of the time. Then you can either replace it fix it or whatever.
You should also try the the easiest fix when it is the problem of checking the fuel cap fit. I have found so many with a big chunk of dirt colored dust packed in there that you can literally suck out if you suck on them with your mouth and it's like a hard pebble.
You can use a small wire or air compressor blow gun tip to clear them out just don't blow the cap apart but usually you're okay.
I had an stx38 a few years ago that somebody brought me that wasn't getting enough fuel through the fuel line so the car bowl level was getting low. I found three ladybugs hiding down the fuel line.
They had probably been in there for years but the tank looked pretty clean. When I got around to blowing backwards on the fuel line the ladybugs and some other crap blew up into the gas tank.
I also had a Cub cadet zero turn that had so much grass that had worked its way down into the fuel line about 2 in past the exit point of the tank that it would start for fuel and not stay running with the blades on under load.
Even though these tanks are supposed to have a strainer or whatever it doesn't mean it always works. And both of these instances it was a very quick easy fix once you do what the problem was..
Luckily I diagnosed it quickly by pulling the fuel line off of the carburetor and found it was very much reduced flow.