Function throws an error after running?

I have a function: MQTTReceiveMsg. It si called ONMQTT. Eg:
ONMQTT “@MQTTReceiveMsg()”

I tracked a bug to this function, but in order to figure out which line specifically is throwing the error, I added a linenumber variable between each line like thus:
LineNumber$=“1”
$ReadMessageLoop:
LineNumber$=“2”
MessageQty%=Mqtt “READ” //Return the number of pending messages
LineNumber$=“3”
IF (MessageQty%>0) Then

LineNumber$=“NaN”
ENDFN

My error handler then logs this when an error occurs:
ERROR:
LOGEVENT "Error in " + FunctionName$ + " on line " + LineNumber$,120

However, my log file is full of this:
Error in MQTTReceiveMsg on line NaN

Are errors only thrown at the end of the function? It seems crazy to me that if there is an error in a function it would continue to run the function and update variables even though an errored state exists.

Hi @Tim_Myth,

The Ewon developers would be best able to answer this question. You can either pose it to them directly on the Ewon Developer Forum, or create a case at support.hms-networks.com that we can escalate to them. I think they are off today for the Easter Holiday however.

Best Regards,

Kyle Reynolds

Tim my guess at this is that the error is somehow getting triggered through the Mqtt “READ” statement. Wonder if the MQTT connection is down at the time of that statement.
Could put the line number into a memory tag and then call the value of the memory tag in the LOGEVENT statement.

1 Like

The function keeps assigning values to LineNumber so I’m not sure that mem tag vs string variable would make a difference, but I’ll give it a shot.