1

I was just reading some answers to this question about slow exceptions. I completely agree with the idea that exceptions can and should used instead of return codes despite of each being considerably slower (although not necessarily noticeable).

I have implemented a circuit breaker in a service that connects to an 3rd party that is called several times on every page request. In the case of a failure, this means that many exceptions are going to be thrown (and logs will be filled as well).

Would this ever be a problem?

Community
  • 1
  • 1
Fabio Milheiro
  • 8,100
  • 17
  • 57
  • 96
  • 3
    Now compare how long it takes to perform a request to a 3rd party service with footprint that brings a thrown exception. – zerkms Oct 23 '14 at 10:36
  • 3
    And think about how much you care about a bit of performance loss if everything is broken already... – Jon Skeet Oct 23 '14 at 10:37
  • @zerkms, that was exactly the problem. We were getting throttled requests from time to time that made the site awfully slow! What we have now is so much better. – Fabio Milheiro Oct 23 '14 at 10:41
  • @JonSkeet (I'm honoured), yes, good point. The conclusion I take from your thought suggestion is we care about throwing too many exceptions but here it's an acceptable issue considering the alternative. – Fabio Milheiro Oct 23 '14 at 10:43
  • Thanks for your thoughts guys. I'd say those comments were answers (even though short). I cannot accept comments. – Fabio Milheiro Oct 23 '14 at 10:43
  • I don't think any of the comments are really answers, but really because the question isn't concrete enough *to* answer. – Jon Skeet Oct 23 '14 at 10:51
  • @JonSkeet, I think it's a question about my concrete doubt. No sure how many would have this doubt and look for it here though. If people vote to delete, I'll end up deleting it. Thanks! – Fabio Milheiro Oct 23 '14 at 10:53
  • We all will share your doubts once we image our lives being on the line with a circuit breaker that delays for raising lengthy exceptions.. ;-) – TaW Oct 23 '14 at 11:21

1 Answers1

1

The way I see it, the circuit breaker is fine the one it is. Someone else (not here) suggested to implement the circuit breaker without raising exceptions as not to log a lot of stuff. That doesn't seem right to me and I haven't been able to think of a nice way of doing that generically as I need the circuit breaker to be used in more than one service (currently 2 - the methods being intercepted by Unity).

The only change I decided to do to my application was to cache the result of the method that calls the 3rd parties. There is no down-side as far as I could see because the data is not changed frequently and we can afford it to be stale.

Fabio Milheiro
  • 8,100
  • 17
  • 57
  • 96