Catch All Error Python Code Example


Example 1: python catch all exceptions

try:     raise Exception("Oh no! An error happened!") except Exception as err:     print("An error was handled") finally:   	print("This runs either way.")

Example 2: catch error data with except python

import sys try: 	S = 1/0 #Create Error except: # catch *all* exceptions     e = sys.exc_info()     print(e) # (Exception Type, Exception Value, TraceBack)  ############ #    OR    # ############ try: 	S = 1/0 except ZeroDivisionError as e:     print(e) # ZeroDivisionError('division by zero')

Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?