וְגָדַ֣לְתִּי וְהוֹסַ֔פְתִּי מִכֹּ֛ל שֶׁהָיָ֥ה לְפָנַ֖י בִּירוּשָׁלִָ֑ם אַ֥ף חָכְמָתִ֖י עָ֥מְדָה לִּֽי׃
Kaya naging dakila ako at nakahigit pa ako sa lahat ng nauna sa akin sa Jerusalem; nanatili rin sa akin ang aking karunungan.
Rambam
And Ben Hey Hey said [that] according to that which you are in pain with Torah will be your reward. And they said that only that which you study with exertion, labor and fear from the teacher will endure; but reading of enjoyment and leisure has no endurance to it and [so] no point in it. And they said in the explanation of his statement (Ecclesiastes 2:9), "even (af, which can also be understood as anger) my wisdom remained with me" - the wisdom that I studied with anger remained with me. And because of this, they commanded to place fear upon the students; and they said (Ketuvot 103b), "Throw fear upon the students."
Kli Yakar
And there are those who say: Based on what is stated Indeed, my wisdom remained with me (Ecclesiastes 2:9) — referring to that which I learned through anger and fury. Regarding this, he [Joseph] said Do not become agitated on the way — meaning don’t learn wisdom through anger. Perhaps they were referring to a matter that requires deep contemplation, as mentioned. And I add a good lesson of reason and knowledge: since all anger leads to error, and our Sages of blessed memory said (Gittin 43a) “A person does not fully grasp a matter of Jewish law unless they first stumble in it.” Therefore, they said that the wisdom I learned through anger and fury, which led me to error, is what ultimately remained with me. For one who makes a mistake in something once will be especially careful about it in the future.