These errors are among the most common in PostScript.
When I get a stack overflow, that is usually a sign that a routine is leaving an object on the stack. If this routine gets called 2000 times, it leaves 2000 objects on the stack, which is too many.
When I get a stack underflow, that is a sign that either: (A) one of the routines in the program doesn't work, and never has or (B) one of the routines in the program works, but expects to be called with some arguments left on the stack.
There is no such thing as a PostScript debugger right now. For now, the best that you can do to debug your program is to put in lots of print statements. Learn to use the PostScript pstack command, and use an online interpreter so you don't have to run to the printer for each debugging cycle.
Use an error handler to learn more about what exactly is happening when your program crashes. (see the comp.sources.postscript FAQ for a list of all PostScript related programs.)
If your code has never worked yet (i.e. you are still writing it) then I find that it helps to put little comments in the margin about the state of the stack. Like this:
Heart pathbbox % lowerx lowery upperx uppery
exch 4 -1 roll % lowery uppery upperx lowerx
I generally put these comments in originally, and then take them out when the program works. Maybe this is a bad practice, in case I ever want to go back and look at the code to modify it!!