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
74
Exceptional Exceptions
mariocj89
2
110
unittest.Mock in detail
mariocj89
0
210
Mocks: Successfully isolating the snake
mariocj89
1
85
Effortless logging: A deep dive into Python logging module
mariocj89
0
730
PyLondinium18 - London python Meetup
mariocj89
0
58
It's time for datetime
mariocj89
0
68
Pythons in the tower of babel
mariocj89
0
91
Other Decks in Programming
See All in Programming
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
230
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
350
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
730
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Featured
See All Featured
Building an army of robots
kneath
302
44k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Practical Orchestrator
shlominoach
186
10k
The Pragmatic Product Professional
lauravandoore
32
6.3k
How GitHub (no longer) Works
holman
311
140k
Optimising Largest Contentful Paint
csswizardry
33
3k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Navigating Team Friction
lara
183
15k
The Language of Interfaces
destraynor
154
24k
Mobile First: as difficult as doing things right
swwweet
222
9k
Done Done
chrislema
181
16k
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!