On Tue, Dec 8, 2020 at 6:41 AM Grant Edwards <[email protected]> wrote:
>
> On 2020-12-07, MRAB <[email protected]> wrote:
>
> > Avoid a 'bare' except unless you _really_ mean it, which is
> > virtually never. Catch only those exceptions that you're going to
> > handle.
>
> And sometimes "handling" is just printing some extra stuff and then
> re-raising the original exception:
>
> try:
> something():
> except:
> print(<whatever might be helpful for troubleshooting>)
> raise
>
Even there, I'd most often use "except BaseException as e:", other
than in a very few situations. The only time I have recently used a
bare except is when making use of the traceback module:
try:
...
except:
with open("notes.err", "a") as err:
traceback.print_exc(file=err)
raise
since print_exc() can go fetch the exception via sys.exc_info().
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list