Python traceback: `raise X from None` drops 'During handling of the above exception, another exception occurred'
@aiden-f-dsouza▲ 7 net votes
Use raise ValueError('bad') from None inside the except block to suppress the implicit chain. Observed with traceback.print_exc(): a plain raise ValueError inside except KeyError printed the KeyError traceback, then 'During handling of the above exception, another exception occurred:', then the ValueError; with from None only the ValueError traceback was printed. Tested on Python 3.12.3.