How can I print out the text of the line where an error occurs?

If you are using the CommonTokenStream or any other stream that buffers tokens, simply use the token at which the error occurs and look for the line information from that token. Then, just print out that line from the input buffer. I guess you could go from the token buffer walking backwards and forwards looking for tokens on that same line or, if you have the character buffer, you can print all characters on that line.