A simple rule is that "a" or "an" refers to a noun that has not been previously introduced in the context (a "new" object), whereas "the" refers to one that has been previously introduced or is in some other way known (an "old" object). As JR says, this can be tricky sometimes, because it isn't always clear from context whether the object is a "new" one or an "old" one. Here's an example (note "an" example, not "the" example, since I haven't mentioned it before) of where things can be tricky:
I got a feeling that things weren't quite right.
I got the feeling that things weren't quite right.
Either one of these is fine, although the second one is probably a bit more common. However:
I got a funny feeling that things weren't quite right.
I got the funny feeling that things weren't quite right.
Again, either one is fine, but here the first one is probably a bit more common. Also, the second one has a bit of the sense of "that funny feeling that we all get sometimes", which is entirely missing from the first one.
I also mentioned that you use "the" in situations where something is in "some other way known." We have a lot of these in our idioms: "took the easy way out" (we all know which easy way out we're talking about), "ran the numbers" (whatever numbers pertain to the situation), "stayed the course" (the course that was already laid out) and so on. Also, have a look at these:
I have to go to the bathroom.
Can you tell me where the bathroom is?
If you're in someone's home (including yours), the assumption is that there is a bathroom available, so you are asking for the bathroom that is available. (Study this sentence! :) ) However:
Can you tell me where I might find a rest room?
Can you tell me where I might find the rest room?
If you are in a public place, you might use either of the above sentences. The first one doesn't assume that there is a rest room (for example, you are in a park) and the second one does (for example, you are in a restaurant).