camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Huffman <>
Subject Handling errors
Date Tue, 03 Jan 2017 18:44:19 GMT
I'm having trouble understanding how to write and use an error handler. The
use case is testing a custom Camel component. I would like to have an error
handler that just collects any exceptions thrown by the endpoint's producer.

I somewhat naively assumed this would be simple. I thought the Camel
framework must catch any exception, add it the exchange, and invoke the
handler's process method. That appears not to be the case.

Below is my attempt. The test is set up so my the producer will throw an
exception. To my surprise, the CaptureErrorHandler.process method is being
invoked twice. my component's producer is never invoked.

But If I remove usage of my my error handler from the RouteBuilder, the
producer is invoked, and it throws an exception that is logged by the

Clearly, I don't understand how error handles are supposed to be used. Can
someone enlighten me, or point me to more detailed documentation? The Camel
documentation for ErrorHandler is pretty light on details. Alternatively,
maybe there's a simpler approach I can take for testing my component.

The RouteBuilder's configure method looks like this:

public void configure() throws Exception {
  errorHandler(new CaptureErrorHandlerBuilder());
      .process(new Counter())

And the CaptureErrorHandlerBuilder and CaptureErrorHandler looks like this:

private class CaptureErrorHandlerBuilder extends ErrorHandlerBuilderSupport

  public boolean supportTransacted() {
    return false;

  public ErrorHandlerBuilder cloneBuilder() {
    return new CaptureErrorHandlerBuilder();

  public Processor createErrorHandler(RouteContext routeContext, Processor
processor) throws Exception {
    CaptureErrorHandler handler = new CaptureErrorHandler();
    configure(routeContext, handler);
    return handler;

private class CaptureErrorHandler implements ErrorHandler {
  public void process(Exchange exchange) throws Exception {
    Exception e = exchange.getException();

    // For now, just log the exception

    if (e != null) {



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message