Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesRe-raising exceptions:
# Python 2 syntaxtry: some_operation()except SomeError, e: if is_fatal(e): raise handle_nonfatal(e)# Python 3 syntaxtry: some_operation()except SomeError as e: if is_fatal(e): raise handle_nonfatal(e)The 'raise' statement with no arguments inside an error handler tells Python to re-raise the exceptionwith the original traceback intact, allowing you to say "oh, sorry, sorry, I didn't mean to catch that, sorry, sorry."
If you wish to print, store or fiddle with the original traceback, you can get it with sys.exc_info(), and printing it like Python would is done with the 'traceback' module.
Re-raising exceptions:
try: some_operation()except SomeError, e: if is_fatal(e): raise handle_nonfatal(e)The 'raise' statement with no arguments inside an error handler tells Python to re-raise the exceptionwith the original traceback intact, allowing you to say "oh, sorry, sorry, I didn't mean to catch that, sorry, sorry."
If you wish to print, store or fiddle with the original traceback, you can get it with sys.exc_info(), and printing it like Python would is done with the 'traceback' module.
Re-raising exceptions:
# Python 2 syntaxtry: some_operation()except SomeError, e: if is_fatal(e): raise handle_nonfatal(e)# Python 3 syntaxtry: some_operation()except SomeError as e: if is_fatal(e): raise handle_nonfatal(e)The 'raise' statement with no arguments inside an error handler tells Python to re-raise the exceptionwith the original traceback intact, allowing you to say "oh, sorry, sorry, I didn't mean to catch that, sorry, sorry."
If you wish to print, store or fiddle with the original traceback, you can get it with sys.exc_info(), and printing it like Python would is done with the 'traceback' module.
Re-raising exceptions:
try: some_operation()except SomeError, e: if is_fatal(e): raise handle_nonfatal(e)The 'raise' statement with no arguments inside an error handler tells Python to re-raise the exceptionwith the original traceback intact, allowing you to say "oh, sorry, sorry, I didn't mean to catch that, sorry, sorry."
If you wish to print, store or fiddle with the original traceback, you can get it with sys.exc_info(), and printing it like Python would is done with the 'traceback' module.