Possible to run a function only if it exists?

Backstory, I am migrating a lot of common code to a library setup. For distribution I will still merge the library and driver into a single file but for development it is easier to keep all my common core code in sync with a library.

Anyway... I have a function in the library where a few drivers need some custom sections added. Is it possible to have a function call in the library code that would not fail if that function does not exist? I am thinking maybe a try { } would work with a blank catch afterwards but not sure if there is something more elegant.

Or maybe I need to look into doing something with a class in the library. I think you can override class methods with regular functions.

There is for drivers

device.hasCommand(command) (returns a boolean)

where command is a string

you can do as you suggest with try / catch

4 Likes