title: Apache Camel | Custom Error Handler to control behavior per Exception
body: <p>Apache Camel provides 2 ways for error handling at context level: <em>errorHandler</em> and <em>onException</em>.</p>
  <p>I am looking for a  solution that provides best of both the worlds in one configuration. <em><strong>What I want is that I should configure one error handler (may be a custom one) and within that custom error handler, I should be able to control the behavior on per exception basis</strong></em>
  For Example:</p>
  <blockquote>
  <p>if I get IOException, I would make 3 redelivery attempts at an interval of 3 seconds</p>
  <p>if I get FileNotFoundException, I would make 5 redelivery attempts at an interval of 10 seconds</p>
  </blockquote>
  <p><em>errorHandler</em> would enable me to use one of the provided Error Handlers and would handle all the exception in a similar ways. For example using this approach I can’t have different redelivery attempts for different exceptions.</p>
  <p>So, here where <em>onException</em> comes into picture, which is equivalent of try-catch at camel context level. I can use this to define per Exception behavior.</p>
  <p>I tried to use a custom bean with Dead Letter Channel in an attempt to control the redelivery attempts from the bean. However, Camel attempts redelivery before it passes the control to the custom bean.</p>
  <p>Any thoughts about implementing the solution that I want.</p>
  <hr />
  <p>Edited after first set of comments seeking more clarity:
  I am aware of this feature of onException. There would be different type of exceptions that can be thrown by the routes. Also new exceptions added added as new routes/processors/transformers are developed once the system goes live. If I use onException, then I (or developers) have to specify each one of them. (I don't want to use the onException(Exception.class) approach.)
  So, this would require adding more onException clauses to the context new exception get added to the system. Also, some exception might require special handling. I don't want to rely on developers for error handling. So,I am looking at a generic solution based on a custom error handler. This will help me to keep the config simple, as I have to specify only one error handler on the context. This error handler would be manageable from a JMX Console as well as provide me the flexibility to handle any exception in a customized way.</p>