More robust support for undefined objects and properties

Wraps the expansion in a try/catch to avoid `TypeError`s when objects or properties are undefined.