Python 3.11: A Guided Tour Through Code Transcripts
Chapter: Error Handling Improvements and except*
Lecture: What Happens When There are Multiple Errors?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We just saw task groups and how awesome they are. They let us kick off a bunch of tasks that are related to each other here.
0:07 We're doing three things. Recording action to an external API. Or recording some action to the log file and we're recording it to the database.
0:17 All three are independent. All three are working with external resources in some way and they of course all could
0:24 crash. Normally when we write code and something goes wrong,
0:29 there is one place where there is an error. Maybe when I called record action to the external api
0:36 it crashed but if it didn't it succeeded, then we go into the next step that either passes or fails succeeds or fails and we go into the next one.
0:45 But with async, especially with these task groups where we have the ability to launch them all at the
0:51 same time. In fact, that's kind of the point of the task group. We could have multiple ones fail, The log could fail and the dB could fail.
0:59 What do you want to know about that when there's an error? Do you want to know the first one? Do you want to know that the log failed before the DB
1:07 did so you get that exception? Maybe you want the last one?
1:11 What if you wanted all of them? So in Python 3.11 we have this exception group that allows us
1:19 to group these multiple errors that it might have come into being as part of something like a task group.
1:26 These are called exception groups and what you get is kind of a hierarchical set of exceptions.
1:32 You get an exception group which itself has inner exceptions which themselves may have inter exceptions and you can dive down
1:38 and see. But in that previous case we would get an exception group with two errors,
1:42 one for the logging and one for the database. But there's also an extension to the language except Star that
1:50 says I want to catch in a single except block. Wanna handle both errors in a single bit of standard -ish that you're willing to see the Stars.
2:00 Standard, standard python, exception handling. Pretty cool. Lets dive in to that works.


Talk Python's Mastodon Michael Kennedy's Mastodon