Better error handling using exceptions by name

This commit is contained in:
Dionisio E Alonso 2015-04-09 16:26:48 -03:00
parent 271fffee79
commit 8b3c471361
1 changed files with 5 additions and 5 deletions

View File

@ -57,7 +57,7 @@ class SystemInformation:
'{}\\0000'.format(reg_key), '{}\\0000'.format(reg_key),
'HardwareInformation.AdapterString') 'HardwareInformation.AdapterString')
reg_keys.add(reg_key) reg_keys.add(reg_key)
except: except FileNotFoundError:
pass pass
video_cards = [] video_cards = []
@ -68,14 +68,14 @@ class SystemInformation:
'SYSTEM\\CurrentControlSet\\Control\\Video\\' 'SYSTEM\\CurrentControlSet\\Control\\Video\\'
'{}\\0000'.format(video_card), '{}\\0000'.format(video_card),
'Device Description') 'Device Description')
except: except FileNotFoundError:
try: try:
device_descrption = get_registry_value( device_descrption = get_registry_value(
'HKEY_LOCAL_MACHINE', 'HKEY_LOCAL_MACHINE',
'SYSTEM\\CurrentControlSet\\Control\\Video\\' 'SYSTEM\\CurrentControlSet\\Control\\Video\\'
'{}\\0000'.format(video_card), '{}\\0000'.format(video_card),
'DriverDesc') 'DriverDesc')
except: except FileNotFoundError:
device_descrption = 'Failed to obtain video adapter.' device_descrption = 'Failed to obtain video adapter.'
video_cards.append(device_descrption) video_cards.append(device_descrption)
return '\n\t'.join(video_cards) return '\n\t'.join(video_cards)
@ -123,10 +123,10 @@ class SystemInformation:
os = get('ProductName') os = get('ProductName')
try: try:
sp = get('CSDVersion') sp = get('CSDVersion')
except: except FileNotFoundError:
try: try:
sp = 'n' + get('CSDBuildNumber') sp = 'n' + get('CSDBuildNumber')
except: except FileNotFoundError:
sp = '(no service pack found)' sp = '(no service pack found)'
build = get('CurrentBuildNumber') build = get('CurrentBuildNumber')
return '{} {} (build {})'.format(os, sp, build) return '{} {} (build {})'.format(os, sp, build)