The silver lining effect predicts that segregating a small gain from a larger loss results in greater psychological value than does integrating them into a smaller loss. Using a generic prospect theory value function, we formalize this effect and derive conditions under which it should occur. We show analytically that if the gain is smaller than a certain threshold, segregation is optimal. This threshold increases with the size of the loss and decreases with the degree of loss aversion of the decision maker. Our formal analysis results in a set of predictions suggesting that the silver lining effect is more likely to occur when: (i) the gain is smaller (for a given loss), (ii) the loss is larger (for a given gain), (iii) the decision maker is less loss averse. We test and confirm these predictions in two studies of preferences, both in a non-monetary and a monetary setting, analyzing the data in a hierarchical Bayesian framework.