The programmer's intent is probably to only catch errors in the key lookup d['x'], but if there is some bug in the implementation of myfunc() or any of the functions called by myfunc() which causes a ValueError to unintentionally be raised, it will be caught by the except.
For dictionary lookups specifically, get() is usually preferable:
something = d.get('x')
if something is not None:
something = myfunc(something)
Or if dictionary may potentially contain None values:
E.g. something like:
The programmer's intent is probably to only catch errors in the key lookup d['x'], but if there is some bug in the implementation of myfunc() or any of the functions called by myfunc() which causes a ValueError to unintentionally be raised, it will be caught by the except.For dictionary lookups specifically, get() is usually preferable:
Or if dictionary may potentially contain None values: