# Catch throwable, ignore, retry

**URL:** <https://discuss.elastic.co/t/catch-throwable-ignore-retry/16569>\
**Category:** Elasticsearch\
**Created:** [March 24, 2014, 8:08pm UTC](https://discuss.elastic.co/t/catch-throwable-ignore-retry/16569 "2014-03-24T20:08:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_Nordvik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrik_nordvik/32/1096_2.png) [@Henrik\_Nordvik](https://discuss.elastic.co/u/Henrik_Nordvik)\
**Post date:** [March 24, 2014, 8:08pm UTC](https://discuss.elastic.co/t/catch-throwable-ignore-retry/16569/1 "2014-03-24T20:08:11Z")

</div>

Hi,

A lot of places in ES are now catching Throwable. There are several commits  
that have changed from catching Exception to catching Throwable.  
For instance, TransportClientNodesService catches Throwable, ignores it and  
retries the operation [1]. Some places it logs it as debug and continues.

Throwable includes OutOfMemoryError, StackOveflowError, LinkageError and so  
on. These are usually unrecoverable problems, so catching Throwable is  
usually not considered a good practice.

I think this looks very odd. Is this intentional? Are you really sure you  
want to continue when you get those errors thrown, no matter what?

"An Error is a subclass of Throwable that indicates serious problems that a  
reasonable application should not try to catch."

- 

Henrik

[1]  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java#L267](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java#L267)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 24, 2014, 9:19pm UTC](https://discuss.elastic.co/t/catch-throwable-ignore-retry/16569/2 "2014-03-24T21:19:17Z")

</div>

I agree that programs that work in an environment with safe and predictable  
resource consumption should always follow an all-checked exception approach.

In reality, ES threads that encounter OOM or suddenly fall short on  
resources like network connections for a few milliseconds can often  
survive, because there are so many threads that can temporarily exceed  
limits. In case of TransportClientNodesService, it is better to let ES  
retry for a certain amount, otherwise the failure would propagate to the  
user app, and ES JVM would exit with failure. Imagine a feeder app that  
would always exit in case of too large docs, or restarting nodes, instead  
of trying to continue...

Jörg

On Mon, Mar 24, 2014 at 9:08 PM, Henrik Nordvik [henrikno@gmail.com](mailto:henrikno@gmail.com) wrote:

> Hi,
> 
> A lot of places in ES are now catching Throwable. There are several  
> commits that have changed from catching Exception to catching Throwable.  
> For instance, TransportClientNodesService catches Throwable, ignores it  
> and retries the operation [1]. Some places it logs it as debug and  
> continues.
> 
> Throwable includes OutOfMemoryError, StackOveflowError, LinkageError and  
> so on. These are usually unrecoverable problems, so catching Throwable is  
> usually not considered a good practice.
> 
> I think this looks very odd. Is this intentional? Are you really sure you  
> want to continue when you get those errors thrown, no matter what?
> 
> "An Error is a subclass of Throwable that indicates serious problems that  
> a reasonable application should not try to catch."
> 
> - 
> 
> Henrik
> 
> [1]  
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java#L267](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java#L267)
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEwd3Zw5sCQ9TkcRO5gq-t7cg1L3cL%2B-Nexsf\_fNAjFNw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEwd3Zw5sCQ9TkcRO5gq-t7cg1L3cL%2B-Nexsf_fNAjFNw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Henrik\_Nordvik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrik_nordvik/32/1096_2.png) [@Henrik\_Nordvik](https://discuss.elastic.co/u/Henrik_Nordvik)\
**Post date:** [March 31, 2014, 3:02pm UTC](https://discuss.elastic.co/t/catch-throwable-ignore-retry/16569/3 "2014-03-31T15:02:11Z")

</div>

I think you misunderstood me. I'm not talking about checked vs unchecked  
here. Catching Throwable vs catching Exception is a different beast.

Specifically in the example I showed you:

try {  
callback.doWithNode(nodes.get((index + i) % nodes.size()), this);  
} catch (Throwable _thisThrowableIsAlwaysIgnored_) {  
// retry the next one...  
onFailure(e);  
}

Also, this is in the client, which means you are hiding potentially  
important exceptions from clients.  
We found one similar catch throwable in the JDK, which meant that we did  
not get any clue as to why our program did not work. We actual had to patch  
the JDK to get the original error printed.

- 

Henrik

On Monday, March 24, 2014 10:19:17 PM UTC+1, Jörg Prante wrote:

> I agree that programs that work in an environment with safe and  
> predictable resource consumption should always follow an all-checked  
> exception approach.
> 
> In reality, ES threads that encounter OOM or suddenly fall short on  
> resources like network connections for a few milliseconds can often  
> survive, because there are so many threads that can temporarily exceed  
> limits. In case of TransportClientNodesService, it is better to let ES  
> retry for a certain amount, otherwise the failure would propagate to the  
> user app, and ES JVM would exit with failure. Imagine a feeder app that  
> would always exit in case of too large docs, or restarting nodes, instead  
> of trying to continue...
> 
> Jörg
> 
> On Mon, Mar 24, 2014 at 9:08 PM, Henrik Nordvik \<[henr...@gmail.com](mailto:henr...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > A lot of places in ES are now catching Throwable. There are several  
> > commits that have changed from catching Exception to catching Throwable.  
> > For instance, TransportClientNodesService catches Throwable, ignores it  
> > and retries the operation [1]. Some places it logs it as debug and  
> > continues.
> > 
> > Throwable includes OutOfMemoryError, StackOveflowError, LinkageError and  
> > so on. These are usually unrecoverable problems, so catching Throwable is  
> > usually not considered a good practice.
> > 
> > I think this looks very odd. Is this intentional? Are you really sure you  
> > want to continue when you get those errors thrown, no matter what?
> > 
> > "An Error is a subclass of Throwable that indicates serious problems that  
> > a reasonable application should not try to catch."
> > 
> > - 
> > 
> > Henrik
> > 
> > [1]  
> > [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java#L267](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java#L267)
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/47ea9472-0606-4107-bc9c-a2dcd85c8d29%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8c704742-8fa0-4c98-a8c5-be2a3834917b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8c704742-8fa0-4c98-a8c5-be2a3834917b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:39am UTC](https://discuss.elastic.co/t/catch-throwable-ignore-retry/16569/4 "2017-07-06T01:39:20Z")

</div>


