Someone could think that Job's statement comes from desperation, but that is proven wrong by what God has said: "Do you believe I treated you like this for any other reason than to reveal your righteousness?" Job, who previously had said, "If I am wicked, woe to me," does not contradict this assumption but reveals the bitterness of life. An evil person would not do that, for he rejoices in this [life]. Above all, Job wants to reveal to his friends the reason why he did not die at the moment of his birth, namely, because he was to be an example of energy and strength. According to a different interpretation, even the life in the flesh is indicated, about which Paul writes, "If for this life only we have hoped in Christ, we are of all people most to be pitied." Job experiences the pleasant as well as the bitter sides of life; no one who has rid himself of the flesh rejoices in wealth or excess, nor is he plagued by hardship. Job has tasted this life and its pleasures, for he was blessed with many good children and was rich and healthy. But since his situation turned into its opposite, he also experienced the reverse of his previous life and acknowledged in real life the vanity of these things. This is why Job teaches us not to long for them by saying, "Why did you bring me forth from the womb? Would that I had died before any eye had seen me, and were as though I had not been."Job expresses this in the form of a prayer, for his burdens were not light and he endured the pains not without feeling them. For it would not have been manful had he not felt his sufferings. But he teaches that he endured the pain with the help of God's power, by praying in gratefulness. Paul also expresses this: "It was not I, but the grace of God that is with me."
Source: COMMENTARY ON JOB 10:18-22