Missing method error when handling exception?

I'm handling an exception with the following code:

catch(Exception ex) {
        log.error "exception polling children:", ex
}

But getting the following error:

I don't understand what could be wrong. I'm passing the log.error() function parameters in accordance with the documentation here:
https://docs.smartthings.com/en/latest/tools-and-ide/logging.html#logging-exceptions
Right? Maybe? ....

That will at least solve the missing method error. Then I still have to figure out why the exception is being thrown to begin with, but that's a different topic I guess.

remove the ,ex

if that works, you will need to extract the message if you want to print it (ex.toString()) or some such

I'm confused by the documentation then. Why does it say I can do this:

catch (e) {
        log.error("caught exception", e)
    }

groovy allows method(args) or method args (see groovy documentation)

The ST exception reporting is not quite the same on HE (but very close).

Again, remove the ,e and see if it works. If it does, then you can try the

ex.toString()
or
${ex?.message}

1 Like

Try this...

catch (e) {
log.error "exception polling children: ${e}"
}

Andy

To be fair, Hubitat's developer docs don't say this, but to be extra-fair, that's because I don't think their docs for log even exist. :slight_smile: I normally do something like Cobra's suggestion above. My guess is that ST allows multiple parameters for their logging methods (enabling that to work), while Hubitat does not. I didn't know ST allowed this, and my guess is that Hubitat either also didn't or didn't consider it important enough to re-implement over here.

1 Like