How to define exception to be thrown through ref in Apache Camel

Archer picture Archer · Apr 30, 2011 · Viewed 16.1k times · Source

Have to throw an exception in my camel route defined in XML. Found throwException statement available from Camel 2.3 which looks like:

 <throwException ref="forced"></throwException>

However, I don't know how to define forced exception class to be thrown. Since same exception could be thrown couple of times with different exception messages - would be good to know if throwException has some other form of definition so exception class and exception message are defined in-place.

Answer

Claus Ibsen picture Claus Ibsen · Apr 30, 2011

The ref is just a reference to a so you can do

<bean id="forced" class="java.lang.IllegalArgumentException">
   <constructor-arg index="0" value="This is forced"/>
</bean>

<camelContext ...>
  ...
</camelContext>