Edit:
Another form would be to exclude the else block and roll the nesting into the try-except, essentially implying an "else" should ConnectRegistry not fail:
reg_a_val = reg_b_val = None
try:
with ConnectRegistry(None, HKLM) as hklm:
try:
reg_a_val = _get_a_val(hklm)
except OSError as err:
# log failure
try:
reg_b_val = _get_b_val(hklm)
except OSError as err:
# log failure
except OSError as err:
# log unable to connect to hivekey
This is done because the outer try-except would need to log failure to even access the hiveroot, whereas the inner try-excepts may or may not fail, but we need to continue even if one does fail. Therefore, the question becomes, is nesting a try-except always considered bad practice, or is a case like this perfectly clear?