You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hans Orbaan <ha...@docdata.eu> on 2016/03/04 09:14:11 UTC

null safe operator on exceptions

Hi all,

In the simple language you can use the null safe operator (?.) to avoid null pointer exceptions. This does not work for the ${exception.stacktrace} like: ${exception?.stacktrace}.

.log(LoggingLevel.WARN, "${exception?.stacktrace}")

2016-03-04 09:04:46,969 [main] org.apache.camel.processor.FatalFallbackErrorHandler - ERROR - Exception occurred while trying to handle previously thrown exception on exchangeId: ID-PC0480-55853-1457078686408-0-2 using: [Pipeline[[Channel[Log(myRoute)[ggggg]], Channel[Log(myRoute)[exchangeExceptionOgnl(?.stacktrace)]], Channel[Multicast[[Channel[sendTo(Endpoint[mock://errors])]]]]]]]. The previous and the new exception will be logged in the following.
2016-03-04 09:04:46,976 [main] org.apache.camel.processor.FatalFallbackErrorHandler - ERROR - \--> Previous exception on exchangeId: ID-PC0480-55853-1457078686408-0-2
2016-03-04 09:04:46,978 [main] org.apache.camel.processor.FatalFallbackErrorHandler - ERROR - \--> New exception on exchangeId: ID-PC0480-55853-1457078686408-0-2

Is this something that could/should be fixed or are there reasons why that doesn't work?

With kind regards,

Hans Orbaan

Re: null safe operator on exceptions

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

The method is called getStackTrace(), so you should do ${exception?.stackTrace}

And the simple function "exception.stackTrace" is not using OGNL but a
special function that also converts the stracktrace to a string. If
you call getStackTrace on an exception it returns an array of stack
elements (not the same).



On Fri, Mar 4, 2016 at 9:14 AM, Hans Orbaan <ha...@docdata.eu> wrote:
> Hi all,
>
> In the simple language you can use the null safe operator (?.) to avoid null pointer exceptions. This does not work for the ${exception.stacktrace} like: ${exception?.stacktrace}.
>
> .log(LoggingLevel.WARN, "${exception?.stacktrace}")
>
> 2016-03-04 09:04:46,969 [main] org.apache.camel.processor.FatalFallbackErrorHandler - ERROR - Exception occurred while trying to handle previously thrown exception on exchangeId: ID-PC0480-55853-1457078686408-0-2 using: [Pipeline[[Channel[Log(myRoute)[ggggg]], Channel[Log(myRoute)[exchangeExceptionOgnl(?.stacktrace)]], Channel[Multicast[[Channel[sendTo(Endpoint[mock://errors])]]]]]]]. The previous and the new exception will be logged in the following.
> 2016-03-04 09:04:46,976 [main] org.apache.camel.processor.FatalFallbackErrorHandler - ERROR - \--> Previous exception on exchangeId: ID-PC0480-55853-1457078686408-0-2
> 2016-03-04 09:04:46,978 [main] org.apache.camel.processor.FatalFallbackErrorHandler - ERROR - \--> New exception on exchangeId: ID-PC0480-55853-1457078686408-0-2
>
> Is this something that could/should be fixed or are there reasons why that doesn't work?
>
> With kind regards,
>
> Hans Orbaan



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2