title: Apache Camel: How to get the exception message inside the doCatch() block?
body: <p>I need to return the message from a thrown exception, or put it in the outmessage. But it does not print the correct message on the frontend.</p>
  
  <p>The camel docs suggest using <code>.transform(simple?...)</code> <code>.handled(true)</code> but most of it is deprecated.</p>
  
  <p>What's the correct way of doing this?</p>
  
  <p><strong>Response:</strong>
  <br>
  <code>&lt;418 I'm a teapot,simple{${exception.message}},{}&gt;</code></p>
  
  <p><br>
  <strong>Route</strong>
  <br></p>
  
  <pre><code>from("direct:csv")
    .doTry()
      .process(doSomeThingWithTheFileProcessor)
    .doCatch(Exception.class)
      .process(e -&gt; {
          e.getOut().setBody(new ResponseEntity&lt;String&gt;(exceptionMessage().toString(), HttpStatus.I_AM_A_TEAPOT));
      }).stop()
    .end()
    .process(finalizeTheRouteProcessor);
  </code></pre>
  
  <p><br>
  <strong>doSomethingWithFileProcessor</strong>
  <br></p>
  
  <pre><code>public void process(Exchange exchange) throws Exception {
          String filename = exchange.getIn().getHeader("CamelFileName", String.class);
  
          MyFile mf = repo.getFile(filename); //throws exception
  
          exchange.getOut().setBody(exchange.getIn().getBody());
          exchange.getOut().setHeader("CamelFileName", exchange.getIn().getHeader("CamelFileName"));
      }
  </code></pre>