"And we know that all things work together for good to those who love God, to those who are the called according to His purpose." (Romans 8:28)
The Bible tells us that if we love God, all things will work together for our good. This doesn't mean we won't experience anything bad anymore, but what it does mean is that even if we undergo bad experiences, we can always look forward to the good that God is doing.
The right perspective
Many of us take that verse to mean God will always make all things work for our good. That's right, but there's a big "if" to that: IF we love God. If we truly love God, we're assured of that good in the midst of the bad.
And if we love God, we'll grow a perspective that sees God's goodness even in the middle of a terrible experience. Like Joseph, we will be able to say with conviction,
"...you meant evil against me; but God meant it for good..." (see Genesis 50:20)
That said, here are some good things that can happen to us in and through bad experiences if we love God.
1) We learn
First, we learn. Bad experiences help shape and mold us into what God wants us to be like: like Jesus. Romans 8:29 tells us,
"For whom He foreknew, He also predestined to be conformed to the image of His Son, that He might be the firstborn among many brethren."
God wants all who are in Christ to be like Christ. He uses all sorts of things to make that happen, and included in the list are bad and often unpleasant experiences. If Christ Jesus had to go through such pain in obedience to the Father, what makes us think we'll just walk in the park to be conformed to His character?
2) We are humbled
Next, we are humbled. Joseph, that young man mentioned above, was a dreamer. From a young age he knew that he was destined for greatness, but his pride had to be taken away from him. And what better way than to break him apart time and again?
Joseph was beaten by his brothers and sold as a slave (see Genesis 37). Later he was falsely accused of sexual charges (see Genesis 39). Later he was imprisoned and was forgotten by the very people that he had helped (see Genesis 40). He was broken again and again, yet God was with him.
When God raised Joseph to become Egypt's administrator (see Genesis 41), all that he had there was a gratefulness to God. Thus, his declaration above.
3) We see God better
Lastly and more importantly, we learn to see God better. If we only go through good times and never go through bad times, we will never get to see just how good He is. Did you know that:
"The Lord is near to those who have a broken heart, and saves such as have a contrite spirit." (Psalm 34:18)
Brokenness, which we often experience when go through bad and difficult times, brings us closer to God. We will never see the full spectrum of God's loving kindness unless we are more receptive to it, and being broken or in need is but one of the ways we see that.