The Retry Loop – Painful to Get Right

GeneralDev.jpg

I've been hardening my ticker plant code for the last several days, and today it's been all about logging more intermediate results and putting in retry loops. The problem I find with retry loops is that if you didn't plan for them in the first place, making it fit in nicely can be kind of tricky. If you plan on your method returning if it can't succeed, then your retry loop needs to be within that method completely.

But what if there's exceptions? Well... you have to try/catch around the code, and then if you get a continued failure, then you have to throw the last one? Maybe you throw a new exception with the last one contained within? Not obvious.

Then there's the really layered code where you're in the middle of a call stack, and you're trying to retry, but some of the methods you call already retry, and some don't. So do you "double retry" on some to cover the others? It's not at all easy to do.

Oh don't get me wrong... you can do it... it's just not easy.

I've been hammering away at a lot of these in my code this morning and I'm getting fewer and fewer instances of needing to get back in the code. It's getting close, that's for sure. It's just not easy.

But then, if it really were, everyone would be able to do it.