I'm connecting to a DB on a server. Sometimes connection closes due to some reasons that really aren't important here.

I have some sort of a global error handling routine that is called from almost all error handlers.

When performing simple procedures that are using the connection and ARE NOT calling any other procedures that also use it, there's no problem. Code breaks, error handling routine is called and everything is OK.

But... when performing more complex procedures that are using the connection and are calling other procedures that also use it, sometimes code breaks in second level procedures (it depends when connection closes). My problem is that in this case first level procedures don't break. They continue working and everything goes just terribly wrong.

I can think of some ways to fix this, but, are too complex since my project is... well, quite big.

Any1?