Skip to content

Commit

Permalink
Try & except
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadelmalah committed Apr 20, 2024
1 parent 74804ab commit ea356d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Exceptions/try.py

This file was deleted.

15 changes: 15 additions & 0 deletions Exceptions/try_except.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
try:
print(5 / 0)
except ZeroDivisionError:
print("Nah, you can't divide by zero!")

try:
f = open("demofile.txt")
try:
f.write("Lorum Ipsum")
except:
print("Something went wrong when writing to the file")
finally:
f.close()
except:
print("Something went wrong when opening the file")

0 comments on commit ea356d8

Please sign in to comment.