Well, that's a very good question. There is something called Godly sorrow, It occurs when one sins or has done something wrong. Godly sorrow is from God, and when someone experiences Godly sorrow as the result he experiences great joy
Psalms 126:5-6 They that sow in tears shall reap in joy...