Refactor to avoid throwing exceptions unnecessarily.

Don't throw from resolve_qualified() if we are only calling it to find out
whether a key exists or not, there is nothing exceptional if it doesn't.

This does make the function signature rather ugly, but this is the price to
pay to avoid changing the existing code too much while avoiding unnecessary
exceptions which are very annoying in practice when running under debugger as
they trigger breakpoints-on-exception.

Avoiding exceptions in the normal code path should also be much better from
performance point of view.