TALK / Reuven M. Lerner / When is an exception not an exception? Using warnings in Python

Published: 04 June 2021
on channel: PyCon US
1,856
56

If your code encounters a big problem, then you probably want to raise an exception. But what should your code do if it finds a small problem, one that shouldn't be ignored, but that doesn't merit an exception? Python's answer to this question is warnings.

In this talk, I'll introduce Python's warnings, close cousins to exceptions but still distinct from them. We'll see how you can generate warnings, and what happens when you do. But then we'll dig deeper, looking at how you can filter and redirect warnings, telling Python which types of warnings you want to see, and which you want to hide. We'll also see how you can get truly fancy, turning some warnings into (potentially fatal) exceptions and handling certain types with custom callback functions.

After this talk, you'll be able to take advantage of Python's warning system, letting your users know when something is wrong without having to choose between "print" and a full-blown exception.

Slides: https://speakerdeck.com/reuven/when-i...


Watch video TALK / Reuven M. Lerner / When is an exception not an exception? Using warnings in Python online without registration, duration hours minute second in high quality. This video was added by user PyCon US 04 June 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,856 once and liked it 56 people.