下一个功能将因某些数据而失败。用try-except块将其包装在哪里更好?
if attr in obj_request:
new_record = GosReestr()
new_record.display_name_department = request.user.profile_ad.department
new_record.set_data(**obj_request[attr][_main_data])
print('before')
new_record.save()
print('after')
这样好吗?
if attr in obj_request:
new_record = GosReestr()
new_record.display_name_department = request.user.profile_ad.department
new_record.set_data(**obj_request[attr][_main_data])
print('before')
try:
new_record.save()
except as e
print('after')
还是将所有内容包装在一个if
块中更好?