Exception not cought

Running following code:

rule "WSRainCounter update"
when
    Item WSRainCounter changed or 
    Time cron "	0 0/1 * 1/1 * ? *"
then
    try{
    	logInfo("WSRainCounter update Rule", "triggered") 
        val lastDelta = WSRainCounter.previousState(false, "influxdb").state
        val lastHour = WSRainCounter.deltaSince(now.minusHours(1), "influxdb")
        val last24h = WSRainCounter.deltaSince(now.minusHours(24), "influxdb")
        val last7d = WSRainCounter.deltaSince(now.minusHours(7*24), "influxdb")
        val last30d = WSRainCounter.deltaSince(now.minusHours(30*24), "influxdb")
      logInfo("WSRainCounter update Rule", String.valueOf(lastDelta)) 
      logInfo("WSRainCounter update Rule", String.valueOf(lastHour)) 
    	logInfo("WSRainCounter update Rule", String.valueOf(last24h)) 
    //	logInfo("WSRainCounter update Rule", String.valueOf(last7d)) 
    //	logInfo("WSRainCounter update Rule", String.valueOf(last30d)) 
        if (WSRainLastHour.state as Number != lastHour as Number) 
            WSRainLastHour.postUpdate(lastHour as Number)
        if (WSRainLast24h.state as Number != last24h as Number)
            WSRainLast24h.postUpdate(last24h as Number)
        if (WSRainLast7d.state as Number != last7d as Number)
            WSRainLast7d.postUpdate(last7d as Number)
        if (WSRainLast30d.state as Number != last30d as Number)
            WSRainLast30d.postUpdate(last30d as Number)
        if (WSRainLastDelta.state as Number != lastDelta as Number)
            WSRainLastDelta.postUpdate(lastDelta as Number)
  	} catch(Exception e) {
        // initiate items
        logInfo("WSRainCounter update Rule", "exception") 
        WSRainLastDelta.postUpdate(0.0)
        WSRainLastHour.postUpdate(0.0)
        WSRainLast24h.postUpdate(0.0)
        WSRainLast7d.postUpdate(0.0)
        WSRainLast30d.postUpdate(0.0)
    }
    logInfo("WSRainCounter update Rule", "exit") 
end

the log shows:

2018-05-25 09:09:00.019 [INFO ] [del.script.WSRainCounter update Rule] - triggered
2018-05-25 09:09:00.288 [INFO ] [del.script.WSRainCounter update Rule] - 556.959999
2018-05-25 09:09:00.293 [INFO ] [del.script.WSRainCounter update Rule] - 3.834999
2018-05-25 09:09:00.297 [INFO ] [del.script.WSRainCounter update Rule] - 13.275000
2018-05-25 09:09:00.324 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'WSRainCounter update': Could not cast NULL to java.lang.Number; line 27, column 13, length 31

That means that exception section is not executed

Notice it says Error, not exception. Xtend is a separate language from Java and it doesn’t use Exceptions for everything. In particular I’ve seen this is the case for casting errors and some parsing errors.

In short, no exception was caught because no exception was thrown.

Has to be accepted as it is.
But on the other side how can I manage my situation about not initialised item. Or is there a possibility to enforce a Java exception, e.g. using different statement.

if(WSRainLast30d.state != NULL && WSRainLast30d.state != last30d)

Note, you probably don’t need the as Number in any of these cases except for lastDelta. deltaSince already returns a Number. If it is complaining about an ambiguous method call without it, change your declaration to val Number lastHour = ....

Thanks.

Probably better

if(WSRainLast30d.state == NULL || WSRainLast30d.state != last30d)

As I want to initiate the Item when it is NULL. The question is: does it evaluate the second expression, for TRUE || ?

I don’t understand the question. With || as soon as a clause evaluated to true it enters the body of the if statement. So in this case if the state is NULL the test whether the state is different from last30d will never occur because the if statement will already evaluate to true.