How to correct an error in a submitted paper? Suppose that after submitting a paper for publication, but before hearing anything back from the referee, I discover an error in the paper that needs to be corrected, or an omission that needs to be rectified.  What is the best course of action?  Should I send a revised version to the editor to forward to the referee, explaining exactly what I have changed?  Or wait to hear back from the referee and then include the fixes in my next version along with whatever other changes the referee suggests (again explaining them to the editor)?
 A: This is a slightly silly comment, but I'll explain why I think it's worth making.
The best answer, of course, is don't make mistakes!
Of course, we're all human (and, ahem, it's not like I haven't had to correct papers which have already been published).  However, I continue to be amazed by how sloppy some papers are which come to me as a referee.  These are often by serious, established mathematicians.  But I'm talking about people managing to cite their own work incorrectly (or get a definition, which they invented, wrong), or major, paper-breaking errors which I, as the referee, spot almost immediately.  I can only imagine that people, once they have proved a result, almost fall over themselves to write it up and send it off.  I'm young, and relatively patient, but I imagine that this behaviour is a good way to get rejected out of hand (even if the, corrected, paper is quite nice).
To answer the original question: as a referee, I would prefer corrections, but I would agree with Pete Clark that this would make me lose faith in the author(s).  If I were an editor: I don't know...
A: I second the answers that have already been given, but you might also consider updating the paper wherever it appears on the internet (your website, the arxiv).  The referee(s) might not have started looking at your paper yet, and when they do, there's a decent chance that they'll download the paper from the arxiv or your website rather than looking at the copy that was actually sent to them by the journal.  
(This comes from experience.  I once had a paper where the referee ended up reading a version that wasn't quite final. I had caught some typos between putting the paper on the arxiv and sending to the journal; but the referee read the arxiv version, so the typos got caught again. This I think one can live with -- I wouldn't update an arxiv submission just to fix typos until the final version -- but if the changes were serious I think it would have been worthwhile.)
A: I think Angelo is right in broad strokes.  For minor errors it's annoying to bother the editor and the referee. But if it's something that the referee might end up wasting hours on then correcting it pre-emptively makes sense.  Here are some examples of things that I'd wait or not on for concreteness.  I'd love to hear from people with more knowledge/experience about whether this is vaguely the right place to draw the line.
Wait when:


*

*An example is incorrect

*A table has some wrong entries

*A technical assumption is missing in the statement of a lemma, but everywhere the lemma is used the assumption holds

*You say something's you've constructed is unique, but really it's only unique up to complex conjugation.

*You're proving some result subject to several technical assumptions, turns out you forgot to include a technical assumption that's no worse than the others.


Contact immediately when:


*

*A result (not just a lemma) in the paper is completely wrong

*A result in the paper may be correct, but the proof is unfixable

*A section needs to be removed or added

*A construction you use doesn't work, it needs to be replaced by a rather different construction.

A: If the error is trivial and you think the referee will overlook it (missing factor of 2, etc), you could wait.  If the error is obvious and you think the referee will see it at once, (you forgot to say the manifold is assumed to be compact, and the theorem obviously fails for $\mathbb{R}^n$), you could wait.  Otherwise, as a referee, I'd rather know about it.  I tend to read papers very carefully and sometimes spend a lot of time deciding whether some obscurity is due to an error or my own ignorance (I'm a younger mathematician and will probably outgrow this eventually :)  A constant stream of corrections would be annoying, but one significant one can be appreciated.
If the error will require major revisions or seriously weaken the result, I'd say notify for sure.  If you aren't yet sure of the fix and think you might need to withdraw the paper, notify for sure, so the referee needn't waste time reading it in the meantime.
A: I somewhat disagree with the answers given so far.  There are great differences among mathematicians (at the cultural level, and also at the individual level) in their attitude to errors in written work.  Some people -- dare I mention continental Europeans? -- are really distressed by coming across a false statement in a paper.  It makes them think that the author is at best "sloppy"; worse, there is the risk that an error that looks silly to you may cause the referee to lose confidence in your work.
Also remember that you know what you meant 100 times more than anyone else, and someone who is struggling to understand an argument which is new to them may not be so willing to correct a trivial error.  In the intermediate level graduate course I am teaching now I am writing up all of my own notes and my own exercises.  Several students in my class write to me periodically to point out trivial errors in my notes: e.g. missing "not"s and such things.  Indeed, I encourage them to do so, because I know that these errors still give my students some trouble: their guesses at what I meant to say are usually correct, but they lack conviction and are thus somewhat nervous that they are misinterpreting something.
So I would say that if you discover that you have made an error in your paper -- again, I mean an incorrect mathematical statement, not a missing citation or a piece of exposition that you have found is more obscure than you wanted -- then you should contact the editor promptly.  If it is easy to correct the error, do so, and enclose the new version of the paper and/or link to your homepage.  The editor and the referee can decide what is truly minor.
Of course, when you contact the editor to say that you have corrected something and made a new version, it's a great time to recheck the rest of the paper.  Sending one or two such "author generated revisions" on a given paper is (in my opinion, of course) being a diligent author.  More than that really does risk annoying and eroding the confidence of the editor and referee.
Addendum: I see from the comments that Kevin Buzzard has expressed the opposite opinion, and he -- unlike me -- is an editor (although I have been a referee many times over and do not mind receiving an unsolicited revision).  So now I'm thinking that the correct answer may depend upon the editor, and that there is no one best policy.
A: If the error is substantial, I would send a revised version immediately, for obvious reasons. Otherwise just wait.
A: If you send a new version, I would recommend to do either of the following (from best to worst):


*

*Add an (autmotatically generated, i.e., reliable) list of all differences. If you use LaTeX, then latexdiff can be very useful for this; if you use MS Word then I assume Word has some mechanism to display differences across versions too (but I am not sure). 

*Send an additional "attachment" instead (giving the correct proof of Thm 2.3), and ask to ignore the proof given in the paper.

*At least, only change the (single) part that absolutely has to be changed (proof of Thm 2.3) and nothing else, do not additionally correct typos on the way or improve the presentation.


Note that 2 and 3 are more reasonable if the change is very localized. If a string of Definitions and Lemmas leading up to the proof has to be changed, got for 1.
It is not enough to just say "We completely rewrite the proof of Thm 2.3, adapt the according definitions, and fix several typos".
Reason: For a careful /detail oriented referee who already went through 20 pages and who checked for correctness, clarity, typos.., it can be frustrating to be told "Hey, look, here is another version, which may or may not be similar to what you read before, but who knows? In any case, the proof of Thm 2.3 is now correct. Have fun!"
