Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception handling 异常处理-尝试捕获不明确行为(?)_Exception Handling_Apache Camel - Fatal编程技术网

Exception handling 异常处理-尝试捕获不明确行为(?)

Exception handling 异常处理-尝试捕获不明确行为(?),exception-handling,apache-camel,Exception Handling,Apache Camel,这是我的密码 from("direct:test-POST") .doTry() .process(new Processor() { @Override public void process(Exchange arg0) throws Exception { throw new NullPointerException(" Null value"); }

这是我的密码

from("direct:test-POST")
        .doTry()
        .process(new Processor() {

            @Override
            public void process(Exchange arg0) throws Exception {
                throw new NullPointerException(" Null value");

            }
        })
        .doCatch(NullPointerException.class)
        .log("${exception}") // This Prints NullPointer Exception
        .process(new Processor() {

            @Override
            public void process(Exchange arg0) throws Exception {
                System.out.println( arg0.getException() ); //This prints Null

            }
        })
        .end();
我正在使用jetty:run来运行这条骆驼路线


如何捕捉异常。它在日志中正确打印异常。但在处理器内部,异常为null。我遗漏了什么

我认为在exchange上的某个属性上发现了异常。比如:

Throwable caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, NullPointerException.class);
assertNotNull(caused);

我认为在交易所的一处房产上可以找到例外情况。比如:

Throwable caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, NullPointerException.class);
assertNotNull(caused);

对的doTry/doCatch将异常标记为已处理,然后它的行为与您在此处看到的相同:正确。doTry/doCatch将异常标记为已处理,然后它的行为与您在此处看到的相同: