Skip to content

Commit f0f67fd

Browse files
committed
Final except* demo code.
1 parent 817e333 commit f0f67fd

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

code/ch04-error-handling/except-star.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,31 @@ class FileException(Exception):
6363

6464

6565
def main():
66+
# asyncio.run(record_action())
67+
6668
try:
6769
asyncio.run(record_action())
68-
except Exception as x:
69-
print("Error:")
70-
print(x)
70+
except* DbException as db:
71+
for e in db.exceptions:
72+
print(f"DbException: Error with DB: {e}")
73+
except* HttpException:
74+
print("HttpException: Error with API")
75+
except* FileException:
76+
print("FileException: Error with file!")
77+
except* Exception as x:
78+
print(f"{len(x.exceptions)} additional errors:")
79+
for e in x.exceptions:
80+
print(f"Error: {e}")
81+
82+
83+
# def main():
84+
# # asyncio.run(record_action())
85+
#
86+
# try:
87+
# asyncio.run(record_action())
88+
# except Exception as x:
89+
# print("Error:")
90+
# print(type(x).__name__, x)
7191

7292

7393
async def record_action():

0 commit comments

Comments
 (0)