Last active
June 8, 2023 10:39
-
-
Save nagos/39172d52f7515eb9cd435a609db48a12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc(x): | |
print("-- Calculating") | |
try: | |
result = 5 / x | |
except ZeroDivisionError: | |
print("-- Expected error, continue") | |
result = 0 | |
print("-- Result ready") | |
return result | |
if __name__ == '__main__': | |
try: | |
print("Run 1") | |
res1 = calc(2) | |
print(f"Result {res1}") | |
except: | |
print("Fatal error") | |
print() | |
try: | |
print("Run 2") | |
res2 = calc(0) | |
print(f"Result {res2}") | |
except: | |
print("Fatal error") | |
print() | |
try: | |
print("Run 3") | |
res3 = calc("test") | |
print(f"Result {res3}") | |
except Exception as err: | |
print(f"Fatal error {err}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: