Here is a passage from the Summa II-I, Q. 39:
[A] thing is said to be good or evil, on the supposition of something else: thus shame is said to be good, on the supposition of a shameful deed done, as stated in Ethic. iv, 9. Accordingly, supposing the presence of something saddening or painful, it is a sign of goodness if a man is in sorrow or pain on account of this present evil. For if he were not to be in sorrow or pain, this could only be either because he feels it not, or because he does not reckon it as something unbecoming, both of which are manifest evils. Consequently it is a condition of goodness, that, supposing an evil to be present, sorrow or pain should ensue. Wherefore Augustine says (Gen. ad lit. viii, 14): "It is also a good thing that he sorrows for the good he has lost: for had not some good remained in his nature, he could not be punished by the loss of good."Compare that with this insight from an article on internet porn:
It is a strange thought to think that we need boredom and anxiety and sorrow as a way of living a functional life, but without the capacity to experience those evils - evils in themselves but not necessarily in context - we would lack the capacity to distinguish good from bad, which, according to St. Thomas, leads to a worse evil:However, anyone who has experienced the power of sex in general and internet pornography in particular to reroute our priorities is unlikely to be so sanguine about liberty. Pornography, like alcohol and drugs, weakens our ability to endure the kinds of suffering that are necessary for us to direct our lives properly. In particular, it reduces our capacity to tolerate those two ambiguous goods, anxiety and boredom. Our anxious moods are genuine but confused signals that something is amiss, and so they need to be listened to and patiently interpreted – which is unlikely to happen when we have to hand one of the most powerful tools of distraction ever invented. The entire internet is in a sense pornographic, it is a deliverer of constant excitement which we have no innate capacity to resist, a system which leads us down paths many of which have nothing to do with our real needs. Furthermore, pornography weakens our tolerance for the kind of boredom which is vital to give our minds the space in which good ideas can emerge, the sort of creative boredom we experience in a bath or on a long train journey.
I answer that, It is impossible for any sorrow or pain to be man's greatest evil. For all sorrow or pain is either for something that is truly evil, or for something that is apparently evil, but good in reality. Now pain or sorrow for that which is truly evil cannot be the greatest evil: for there is something worse, namely, either not to reckon as evil that which is really evil, or not to reject it. Again, sorrow or pain, for that which is apparently evil, but really good, cannot be the greatest evil, for it would be worse to be altogether separated from that which is truly good. Hence it is impossible for any sorrow or pain to be man's greatest evil. (Q. 39, art. 4.)Cooperating with evil, and being indifferent to evil, is worse than sorrow and pain.