* @param type the exception type
* @see Exchange#getException(Class)
* @return an expression object which will return the exception set on the exchange
*/
public static Expression exchangeExceptionExpression(final Class<Exception> type) {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
Exception exception = exchange.getException(type);
if (exception == null) {
exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
return ObjectHelper.getException(type, exception);