Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Exceptional Exceptions - EuroPython 2019
Search
Mario Corchero
July 11, 2019
Programming
1
110
Exceptional Exceptions - EuroPython 2019
Mario Corchero
July 11, 2019
Tweet
Share
More Decks by Mario Corchero
See All by Mario Corchero
Linux & Python
mariocj89
0
72
Exceptional Exceptions
mariocj89
2
99
unittest.Mock in detail
mariocj89
0
200
Mocks: Successfully isolating the snake
mariocj89
1
84
Effortless logging: A deep dive into Python logging module
mariocj89
0
720
PyLondinium18 - London python Meetup
mariocj89
0
58
It's time for datetime
mariocj89
0
63
Pythons in the tower of babel
mariocj89
0
87
Other Decks in Programming
See All in Programming
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
Realtime API 入門
riofujimon
0
110
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
400
CSC509 Lecture 08
javiergs
PRO
0
110
Macとオーディオ再生 2024/11/02
yusukeito
0
190
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
現場で役立つモデリング 超入門
masuda220
PRO
13
2.9k
Golang と Erlang
taiyow
8
1.9k
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.4k
Featured
See All Featured
What's new in Ruby 2.0
geeforr
342
31k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Statistics for Hackers
jakevdp
796
220k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
GraphQLとの向き合い方2022年版
quramy
43
13k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
107
49k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Unsuck your backbone
ammeep
668
57k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Transcript
© 2019 Bloomberg Finance L.P. All rights reserved. Exceptional Exceptions:
How to properly raise, handle and create them EuroPython 2019 July 11, 2019 Mario Corchero @mariocj89
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Let’s just raise an exception, right?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Let’s just raise an exception, right?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Let’s go step by step
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. How to capture an exception
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. What can go in the except?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. What can go in the except?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Using finally
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Using else
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Order of execution?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. What about returning in the middle?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions Use exc_info to include exception information
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions Errors should never pass silently. Unless explicitly silenced.
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions But... When I have...
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions But... What if I know...
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Logging exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Scoping of the except See PEP 3110. In short: exception -> traceback -> stack frame -> exception
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Raise it!
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. The tricky, raise within except
© 2018 Bloomberg Finance L.P. All rights reserved. The tricky,
raise within except
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Reraise
© 2018 Bloomberg Finance L.P. All rights reserved. Reraise
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Reraise
© 2018 Bloomberg Finance L.P. All rights reserved. Reraise
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Chaining exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. Chaining exceptions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Eliding previous exception
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Eliding previous exception
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. False friends: NotImplemented Passes without printing. 37,762 hits in GitHub as of July 2019.
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Raise on a thread?
© 2018 Bloomberg Finance L.P. All rights reserved. Raise on
a thread?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. The exception hierarchy Check https://docs.python.org/3/library/exceptions.html
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Exception attributes
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Exception attributes
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Exception attributes
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Creating new classes
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Creating new classes
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Exception hierarchy
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Multiple inheritance • Decimal: • Requests:
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Can I use Error codes?
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Conclusions
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Extra content!
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. New magic in 3.8
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. New magic in 3.8
© 2019 Bloomberg Finance L.P. All rights reserved. Cycles when
reraising
© 2019 Bloomberg Finance L.P. All rights reserved. Cycles when
reraising
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Returns in finally
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Returns in finally
© 2018 Bloomberg Finance L.P. All rights reserved. © 2019
Bloomberg Finance L.P. All rights reserved. Returns in finally
© 2019 Bloomberg Finance L.P. All rights reserved. Thank you!
Questions?? Also, ask me about travelling to Extremadura!