var phantom = this.phantom || {exit: function () {}}; var foo = {bar: {baz: 123}}; delete foo.bar; try { console.log(foo.bar.baz); } catch (err) { console.log(err); phantom.exit(); }