I once read about a psychological study that compared the effect on children of praising intelligence versus praising effort. If a child is usually rewarded for accomplishment with phrases like "You're so smart!", then the child is likely to value intelligence over effort. Consequently, when the child fails at something, he or she usually attributes the failure to a fault in intelligence and is not very motivated to try again. If a child is usually rewarded for accomplishment with phrases praising effort, then he or she is likely to try again, believing any obstacles are probably surmountable through persistence and adaptation.
That's what I thought of when I read Shwayder's excellent post on rewards and punishments. Ryan talks about how lows and highs are relative to one another. Accomplishment feels greater when something is risked in the struggle (pride is always risked, but its power varies greatly from one personality to another). In the end, Shwayder emphasizes rewards for effort.
I'd bet that adequately rewarding effort makes it easier for players to stomach tough punishments. Perhaps, the more effort is rewarded, the harsher punishment can be without diminishing fun.
Think of sports. If your team loses a game, there's no replaying that game. You can have a rematch later, but that loss is still on your record, a significant memory (especially for rivals). If you have a good coach, he's going to point out both your mistakes and your progress. Losing is never a fun feeling, but it's more bearable when you receive recognition for admirable actions or improved performance.
In college football, players accrue individual stats independent of team performance. A good player on a losing team is often recognized for individual achievement. Replay highlights help to remind losers of their better moments, not just the bad. In Goldeneye64, a player might lose and yet smile at receiving the "Most Dishonorable" award. In LOTR: Battle for Middle Earth 2, the pain of losing a battle is sometimes offset by enjoying an epic event, like a Balrog setting dozens of soldiers aflame.
One thing that's rarely seen in games, because it's hard to program, is pointing out mistakes. The usual scenario is that a player can try a challenge over and over and over, yet always have to figure out mistakes on his own. Coaching mechanics still have a long way to go in games. Even in multiplayer games, you can't rely on players to seek out advice from other players, though highlighting good instructors in community resources can be good.
I'm certain that rewarding effort and coaching can help keep a game fun through loss and punishment. What I'm not certain about is how exact and predictable the relationship is. I'd play it by ear.