It did not happen to me so far, but as an editor or some (very good) journals, I handled several such papers. I also found errors in papers that I refereed. This is not uncommon, and you should not worry too much about it. What happened to me once was that after my paper was accepted, I discovered that one of the main results has been previously published (the funny thing about it was that I did ask the author of that result before submitting the paper whether my result was new, and he did not remember his own paper.)
It depends on the referee, of course. In general you cannot control much what other people think about you, and you should not be too concerned about it. Just try creating a better paper next time.
"Very good" journals like Inventiones do not consider resubmitted papers, as far as I know. So you should not resubmit your paper unless a letter from the editor specifically invites you to do that. But there are many other very good journals. I know several cases when after a mistake was found in a paper, it was fixed, and the results actually became much better looking (and correct).
|1||[made Community Wiki]|