Towards the end of the parsha, Yosef's brothers plead with him to not take revenge or otherwise punish them for what they had done to him. Yosef responds that although their intentions were bad, since Hashem intended it for a good purpose, namely to keep everyone alive, he would not consider harming them at all.
Very often something which we consider an absolute tragedy occurs, and only years later, when looking back and placing all events into the proper perspective, do we realize that the tragedy was not at all a tragedy, but rather enabled something wonderfully good and marvelous.
In Parshas Miketz (42:36) Yaakov Avinu is so distraught; his whole life is falling apart: Yosef is gone, Shimon is gone, and now they're taking away his beloved Binyamin. The medrash comments on that passuk that Hashem was sitting in heaven above and chuckling at Yaakov's "krechzing". Yosef is gone? He's the prime minister of Egypt and is on top of the world! Shimon is gone? He's roaming about freely touring Egypt! Yosef only imprisoned him as long as the brothers were there (See Rashi to Parshas Miketz 42:24). And now Binyamin too will be lost? Nothing at all happened to Binyamin, just like nothing at all happened to Yosef or to Shimon. Yaakov's perception was that he had experienced tragedy upon tragedy, while in truth nothing had gone wrong at all.
The Talmud (Berachos 60b) tells us that when we experience a tragedy we must recite a special blessing, barcuh dayan haemes, and that beracha should be accompanied by acceptance of the tragedy with great simcha based on the belief that everything that Hashem allows to happen is always for the good! When the Torah commands us (Devarim 25) to wipe out the nation of Amalek, the expression used is that they should be wiped out "mitachas hashomayim - from under the heavens". The implication is that only from our perspective should Amalek be wiped out, as they are the physical embodiment of evil.
However, from Hashem's perspective, which takes into consideration the totality of all events, even Amalek embodies some good. This is what the rabbis in the Talmud had in mind when they pointed out (Gittin 57b) that descendents of Amalek and other evil individuals converted to Judaism and learned and taught Torah. Although we view Amalek as the ultimate symbol of evil, history has proven that even they had some redeeming value.
Whenever we experience any tragedy we should always adopt the attitude of Rabbi Akiva (Bearchos 60b) who would always assume that G-d would not have permitted the event to occur if it weren't something good. Rabbi Akiva learned this approach from his rebbe - Nachum Ish Gam Zu, who would always comment upon experiencing tragedies, "this too is certainly something good!" (Taanis 21a).