kuroko/test/testMultipleExcept.krk
2021-03-18 19:52:30 +09:00

28 lines
554 B
Python

class SpecialException(ValueError):
pass
def exceptionFilter(exc):
print('with',repr(exc))
try:
if exc: raise exc()
print("None")
except TypeError:
print("TypeError")
except ValueError:
print("ValueError")
finally:
print("Running finally")
print("Function exit")
exceptionFilter(None)
exceptionFilter(TypeError)
exceptionFilter(ValueError)
exceptionFilter(SpecialException)
try:
exceptionFilter(NameError)
except Exception as e:
print("NameError was not caught:", repr(e))