Is "what the hell" used as just an expression, or is it considered offensive? In what situations is it "okay" to use it? If it is offensive, is there a more "polite" alternative which expresses the same feeling?
Note that what the hell (or the more common and even more offensive what the fuck) is a short form for something like...
What the hell is going on?
So just omit the "potentially offensive" bit in the middle. According to context, it might be you need to say "What are you doing?", or "What is that?", but hopefully the general principle is clear.
Lots of people probably think of "hell" above as a "toned down" variant on "fuck". You could tone it down even more by saying "What the heck", or "What the blazes", for example, but increasingly I think such euphemisms are seen as somewhat dated. Either swear or don't - there's no point in pussyfooting around with expressions that are really just attempts to swear without literally doing so.
Arguably just a personal opinion, but I think as a rule non-native speakers may well be judged more harshly than native speakers when it comes to "offensive" language. I believe most people (not just parents) are more likely to be bothered by children swearing than by adults using the same language. Whether you like it or not, it's unavoidable that many people will (consciously or unconsciously) conflate "inarticulate" foreigners with native children who are also in the process of learning English.
Therefore, although I can understand why people learning English are often particularly interested in learning how to use swear words (hoping to sound more like native speakers), I think this is a misguided approach. Personally, I believe swearing effectively/"correctly" is quite an art - which even most native speakers never really master, because it's so much more context-sensitive than most language usage.
In polite circles it would be considered offensive, yes.
There are a couple of geographically related, non-offensive alternatives:
What on earth ... ?
What in heaven's name ... ?
Less offensive (but still not to be said in front of mum):
What the heck ... ?
Contrary to other opinions, I think there is nothing wrong with adding some extra emphasis to what you are trying to say, and attempting to do this while not offending the listener is an admirable goal. What on earth? isn't 'pussyfooting around swearing' at all - it's totally non swearing, but still gets the message across. As an example, when the boss says 'what are you doing?', you'd let him know about your current tasks, but when he says 'what on earth are you doing?', you know you have to justify why you're goofing off.
No, because typically it’s not an offensive comment directed towards someone. It’s more of an exclamatory statement about a situation. If you are directing this comment towards someone or using it to comment about a person’s actions, then yes it may be offensive as a form of criticism.
Hell is not as vulgar of a word in comparison to other “swear words”. In America, the FCC permits the use of this word on TV and radio.
Some polite versions could be:
What is happening? How could that happen? What were you thinking?