E.g. it's a signal that there are bugs, and they need fixin'. What do you do when this happens? Give up on the whole project? NO! You dig in, dig deeper, and figure it out. Yes, it is a matter of ego, at least at first.
That's what meditation is for. I like http://dhamma.org but there's others. It works.
- death is a final state
- it always happens, sooner or later
- there are ways to alleviate pain, whether physical or moral (drugs and such)
- suicide is a capital sin
Even if death seems or is a better option, it makes sense to wait for it (and even to hope for it - there are really bad moments in anyone's life).
And if you do not believe in god, the first 3 items are good reason enough to wait, and a valid 4th one can be :
- suicide means killing perfectly good organs, than in other situations could have save many people needing transplants.
Feelings and emotions are fallible, especially during depression, a disease of our emotion-processing system.