The exception (and I've had way too much experience from multiple perspectives over the past twelve months) is when learning that a friend/co-worker/student/acquaintance's relative has passed away. No matter the specifics of the the situation (young or old, surprising or expected, close or distant), there's usually three ways to react...and there's never any telling which one is appropriate to the situation. If I had to boil it down...you have the choice of being sympathetic, empathetic, or present.
Learning of a tragedy typically yields a sympathetic reaction from everyone. Even as the news and details are still coming in, it's the immediate, involuntary reaction that we all feel. It might not be that you personally feel bad for the loss, but you feel bad that they feel bad. You can understand their pain, though perhaps you don't feel it yourself. In many cases, this reaction is more than enough, especially if you're not especially close to any of the players involved. Sometimes there's no need to feel a situation, sometimes it's enough to simply acknowledge it from afar and be understanding for those involved.
The second reaction, the one those closer to the inner circle often gravitate towards, is empathetic. Sometimes to understand a situation isn't enough, sometimes it's better and even required that you feel the loss in the same way. By putting yourself in the same emotional state as those suffering the loss, you become a more relatable shoulder to lean on, rather than just a distant "understander". Many can benefit when surrounded by empathetic friends...and often times friends feel it's the duty to save the day with empathy. There's that natural reaction to take someone else's pain on yourself and deal with it both with and for them.
The third reaction, however, is a little different, and perhaps a little counterintuitive. Because while some people require sympathy, and others desire empathy...sometimes what's most helpful is just to be...present. As much as we as spectators, friends, co-workers, or acquaintances may want to help, sometimes there's value in allowing someone to own their grief alone. Sometimes people don't want to "feel better" or hear that we "know how hard it is". Sometimes hearing "let me know if there's anything I can do" just doesn't cut it, and sometimes listening to a friend ask "so how are doing?" does more harm than good. Sometimes it's not about sympathy, or empathy. Sometimes it's just about letting them know you're there (physically or mentally)...and that's it. The situation will improve on it's own without any outside force trying to "fix" anything. And sometimes, those in grief don't want anything to be fixed..at least not for a while. Be present; that's all that you need to do.
Are these three approaches based on a sociological study? Nope (though maybe, it's not my field). I just made them up off the top of my based on my experiences from multiple sides of this situation over the past year. Each situation works in different times, for different people, and in varying degrees. Sometimes there are no words...so the first step instead is simply "what's the most helpful way for me to feel?" Sometimes the best thing you can do...is to do nothing with all your might.