Gracefully handle exception being "(None, None, None)"
See original GitHub issueHi!
The built-in traceback
module handles (None, None, None)
tuple (returned if sys.exc_info()
is called outside the context of an exception) without raising an error:
import traceback
traceback.print_exception(None, None, None)
# 'NoneType: None'
Using stackprinter
, however:
import stackprinter
stackprinter.format((None, None, None))
# ValueError: Can't format (None, None, None). Expected an exception instance, sys.exc_info() tuple,a frame or a thread object.
You may argue that formatting such exception is pretty useless… You’re right. 😄
Still, in my situation it happens that the exception tuple looks more like (TypeError, None, None)
(I’ll save you the details, but it happens if the error value can’t be serialized, then it is replaced by None
by default). In such case, it would be nice to format the error like TypeError: None
for example instead of raising a ValueError
. That would be useful so that user could format any exception-tuple without having to check for edge cases like that.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
How to handle errors with grace: failing silently is not an ...
It's fine if you care about different kinds of errors which need to be handled differently, but do your users a favor and...
Read more >Why is the error handling not working for None input?
When you provide None as an input, it doesn't pass the if statement and falls through so nothing is returned and no exception...
Read more >30. Errors and Exception Handling | Python Tutorial
An exception is an error that happens during the execution of a program. Exceptions are known to non-programmers as instances that do not...
Read more >Clean Code and the Art of Exception Handling
Exception Handling: It's a Good Thing · Always create your own ApplicationError hierarchy · Never rescue Exception · Never rescue more exceptions than...
Read more >9 Best Practices to Handle Java Exceptions
Handling Java exceptions isn't easy, especially for beginners. Read this post to understand exceptions and best practices for using them.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Saw this, thank you. Already updated my installation 👍
cc @JulianOrteil ☝️