except:
@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2903 / 12833)
How to use try:
and ʻexcept: `is posted.
I've tried.
http://ideone.com/mhkPBd
alist = [ '7of9', 'Janeway', "B'Elanna Torres" ]
position = 5
try:
print(alist[position])
except:
print("Position is out of range")
run
Position is out of range
except exceptiontype as name:
@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2919 / 12833)
I've tried.
http://ideone.com/rhOmZ8
alist = [ '7of9', 'Janeway', "B'Elanna Torres" ]
position = 5
try:
print(alist[position])
except IndexError as err:
print("Position is out of range")
except Exception as other:
print("Something doesn't sit right well.")
run
Position is out of range
Reference: 5. Built-in exceptions @ Python >> 3.6.1 >> Documentation >> Python standard library
Recommended Posts