Gallows humor is humor about very unpleasant, serious, or painful circumstances. Any humor that treats serious matters, such as death, war, disease, and crime, in a light, silly or satirical fashion is considered gallows humor. Gallows humor has been described as a witticism in response to a hopeless situation. It arises from stressful, traumatic, or life-threatening situations, often in circumstances such that death is perceived as impending and unavoidable.
Sigmund Freud in his 1927 essay Humour (Der Humor) puts forth the following theory of the gallows humor: "The ego refuses to be distressed by the provocations of reality, to let itself be compelled to suffer. It insists that it cannot be affected by the traumas of the external world; it shows, in fact, that such traumas are no more than occasions for it to gain pleasure." Some other sociologists elaborated this concept further. At the same time, Paul Lewis warns that this "relieving" aspect of gallows jokes depends on the context of the joke: whether the joke is being told by the threatened person themselves or by someone else.