As someone on the other side of this, I'll give you my preferred scenarios. Some of these have been iterated by other people, but I'll go into a bit more explanation:
1) If this is something truly urgent, come interrupt me regardless. If everything is urgent to you, then we would have a problem.
2) If you're stuck on something, and have put time into researching your problem, I like to get an IM (Skype, Slack, what have you). However, don't just do a "Hey". I've seen too many times where if I take a minute to respond to that, you're no longer waiting for my response so I've broken my concentration for nothing.
If you have put some effort into your problem, and it isn't complicated, just include the question over IM. Let me get to it in a couple minutes. If you know how to ask a question, I've been able to reply with the exact fix in the past.
If the problem is more complex, then send your message as "I'm having a problem on x, and could use a few minutes of your time."
3) Email is tricky, and depends more on the environment. If your company is constantly sending emails back and forth, your request could easily get lost in the sea of other messages. This could vary drastically with your manager/superior, so feel free to ask "If I email you a question, is that going to be a problem?"
My main approach to all this is very simple: I want to help you. Aiding the people I work with helps me out by allowing me to not have to worry about doing it. It is perfectly fine to have problems. If you're new to the career, we know that when we brought you on, and are aware we will need to spend more time with you.
However, please respect my time by coming with a question prepared. Show me what you've tried to fix it. Do the research trying to find where the code stopped working, and what it did. Again, if it is a rare situation that you have no clue, that's fine as long as it doesn't happen all the time and you aren't new.