try catch 是 Java 里的,try except 是 Python 里的。
try... else... finally...
try:
result = 10 / 2
except ZeroDivisionError:
print("Cannot divide by zero.")
else:
print("Division successful!")
finally:
print("This block always executes.")
捕获所有异常:
try:
...
except Exception as e:
...
多个except异常:
try:
...
except ValueError as ve:
...
except ZeroDivisionError as zde:
...
网友评论