Submission of a paper with a serious error to a good journal I recently obtained (or so I thought) a good result, and after a month of reading and rereading what I'd written, submitted my paper to a very good journal. I'm early in my career (got my Ph.D. a few years ago) and have published 2 papers in good journals; so I figured I'd aim for a top journal this time. 
Unfortunately, I just got an email from the journal indicating that the anonymous referee had found a serious, probably unfixable error in my paper, and that (obviously) they don't recommend it for publication. After looking at it, I realize that I really should have caught this error: although it is a relatively subtle error buried inside of a technical lemma, it still is an obvious error once you notice it. I'm frustrated that I missed this mistake and I'm embarrassed to have wasted the time of the referee, who probably spent a lot of time combing through my paper before they found the error.
So here are my questions.
1) Has this happened to anyone else? Is this a relatively common occurrence, or am I just sloppy?
2) The anonymous referee is probably someone distinguished in my field. Do they now have a bad impression of me? (This probably is not a question that can easily be answered . . . .)
3) If I manage to patch up this paper, is it reasonable to resubmit it to this journal, or have I burned my bridges there?
I'm going to make this community wiki, since I don't know if there's a "right" answer.
 A: This happens. I don't know how common it is, but it has happened to me when I was a Ph.D. student. I think most referees and editors would treat your future work on its own merit, without holding this against you, unless of course you are dispatching big conjectures on a regular basis (e.g. if you are a regular contributor to the General Mathematics section of the arXiv :-)) or you continue to not accept that your proof was wrong. My personal experience with other researchers more knowledgeable than me in the topics of my interest has been good, and I know they know my past mistake.
A: 1) Has this happened to anyone else? Is this a relatively common occurrence, or am I just sloppy?
It is not very common (the usual preventive techniques include showing the draft to a few experts/friends, putting it on ArXiV, letting it lie for a month or two and then rereading it, etc. before sending it to a "top" journal) but it happens now and then. What is common is severe difficulty with finding an error in one's own work. I would say that affects more than a half of mathematicians I know. The reason is that you read not what is written but rather what you believe should be there when you just finish typing the manuscript and start proofreading. The main trick of good proofreading is to turn yourself into a complete idiot, who doesn't see a single step ahead, has no idea of the overall structure of the argument, takes everything literally, and is not convinced of anything that is not clearly put in a modus ponens form. Needless to say, it is about as hard for a shrewd person to read like that as for a genuinely stupid one to read between (or over) the lines. And even if you know all that, you are still destined to submit or even publish papers with errors. Just a few months ago, I was informed about an error in one of mine published papers. It was just a remark and the statement was actually correct, but the proof wasn't. So, to have this kind of public shame now and then is almost inevitable whether you are an unknown postdoc, or Andrew Wiles, or something in between.
I'm not sure if Poincare published a single formally correct proof in his lifetime and people still are completely puzzled by some passages in Linnik's works, so you are in a good company.  
2) The anonymous referee is probably someone distinguished in my field. Do they now have a bad impression of me? (This probably is not a question that can easily be answered . . . .)
It is actually easy to answer: most likely, for him you are nobody, your name is just a random combination of letters, and your "initial value" is zero. An erratic paper leaves it this way, so nothing is lost. We are all getting worthless papers to referee every month and I challenge everyone to recall the name of the author of some bad paper he rejected 6 months ago. The only scenario in which "someone distinguished" would bother to take a mental record of your name after looking at a single opus of yours is when he finds something interesting and unusual in your work. Then your value for him is currently positive, though, of course, not as high as it would be if you solved the problem. So, again, there is absolutely nothing to worry about. 
3) If I manage to patch up this paper, is it reasonable to resubmit it to this journal, or have I burned my bridges there?
Of course, it is. What matters is not how many mistakes you made on the road and who saw them but whether you finally reached your destination and whether other people consider that destination worth reaching. The theorem and its correct proof lose nothing in value if somebody published or tried to publish 20 false proofs before that. That some of those false proofs might be proposed by a person with the same name and biometrical characteristics as those of the one who finally found a correct proof changes nothing in the grand scheme of events. So, if you manage to fix the error and make sure that the argument is, indeed, correct, I see absolutely nothing wrong with submitting it again because from a purely logical standpoint, it is a different paper. If you get it returned solely on the grounds that the previous version was incorrect and not based on the merit considerations (even correct and good papers get rejected sometimes for various reasons), it'll merely tell you that the jornal is not really "top" but just "snobbish", in which case I would avoid it altogether in the future (at least, until they change the editorial board).
A: *

*It did not happen to me so far, but as an editor for 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). 
