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
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
110
Golang と Erlang
taiyow
8
1.9k
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
僕がつくった48個のWebサービス達
yusukebe
18
17k
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.1k
C#/.NETのこれまでのふりかえり
tomokusaba
1
160
Featured
See All Featured
Making Projects Easy
brettharned
115
5.9k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Documentation Writing (for coders)
carmenintech
65
4.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
How GitHub (no longer) Works
holman
311
140k
Building Adaptive Systems
keathley
38
2.2k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
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!