title: How to access exception in Camel errorHandler?
body: <h1>Use Case</h1>
  
  <p>I'd like to log unhandled exceptions for a particular route in Camel in a reusable manner. Specifically, I'd like to extract enough information from the exception and write it to the database, which is then read by some monitoring software. Through the use of a dead letter queue, I was able to have all unhandled exceptions for a specific route routed there. Unfortunately, the exception in the exchange is always <code>null</code> when it is passed to the logger.</p>
  
  <h2>Sample Code</h2>
  
  <p>The code below forces an exception to be thrown, which is then routed to the error handler. I was expecting <code>exchange.getException()</code> to return the exception that was thrown, but in this case it is <code>null</code>.</p>
  
  <h3>Java Code</h3>
  
  <pre><code>public class JobRunner {
  
      public void run(Exchange exchange) {
          throw new RuntimeException("Hello, World!");
      }
  
      public void processException(Exchange exchange) {
          Exception e = exchange.getException();
          // e is null
      }
  
  }
  </code></pre>
  
  <h3>Camel Config</h3>
  
  <pre><code>&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
  
      &lt;errorHandler id="jobErrorHandler"
          type="DeadLetterChannel"
          deadLetterUri="seda:errorHandler" /&gt;
  
      &lt;route id="routeErrorHandler"&gt;
          &lt;from uri="seda:errorHandler" /&gt;
          &lt;bean ref="jobRunner" method="processException" /&gt;
      &lt;/route&gt;
  
      &lt;route id="scheduled_job" errorHandlerRef="jobErrorHandler"&gt;
          &lt;from uri="quartz2://test/job?cron=0+*/5+*+*+*+?" /&gt;
          &lt;bean ref="jobRunner" method="run" /&gt;
      &lt;/route&gt;
  
  &lt;/camelContext&gt;
  </code></pre>
  
  <h1>Questions</h1>
  
  <ul>
  <li>How can exceptions be routed to an error handler?</li>
  </ul>