kuroko/test/testMultipleExcept.krk

28 lines
554 B
Python
Raw Normal View History

2021-03-18 13:52:30 +03:00
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))