Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lecture 7 P.112-114 Try, Except

Snippet info

Language

Python

Visibility

public

Author

tonyngswell

Created

2026-04-30T13:54:26.348871Z

Updated

2026-04-30T14:00:33.463354Z

try:
    x=1
    y=1
    if x==1:
        raise
    result=x/y
    print(result)
except ZeroDivisionError:
    print("second variable cannot be zero")
except TypeError:
    print("one of the operand data type is wrong")
    print(msg)
# TypeError ZeroDivisionError:
except :
    print('exception error')
else:
    print("no error")
# else will only run when there is no error

    
finally:
    print("this line is gonna run no matter what bruh")
    #it is used for file closing
INFO