1AssertionError #Raised when assert statement fails.
2AttributeError #Raised when attribute assignment or reference fails.
3EOFError #Raised when the input() functions hits end-of-file condition.
4FloatingPointError #Raised when a floating point operation fails.
5GeneratorExit #Raise when a generator's close() method is called.
6ImportError #Raised when the imported module is not found.
7IndexError #Raised when index of a sequence is out of range.
8KeyError #Raised when a key is not found in a dictionary.
9KeyboardInterrupt #Raised when the user hits interrupt key (Ctrl+c or delete).
10MemoryError #Raised when an operation runs out of memory.
11NameError #Raised when a variable is not found in local or global scope.
12NotImplementedError #Raised by abstract methods.
13OSError #Raised when system operation causes system related error.
14OverflowError #Raised when result of an arithmetic operation is too large to be represented.
15ReferenceError #Raised when a weak reference proxy is used to access a garbage collected referent.
16RuntimeError #Raised when an error does not fall under any other category.
17StopIteration #Raised by next() function to indicate that there is no further item to be returned by iterator.
18SyntaxError #Raised by parser when syntax error is encountered.
19IndentationError #Raised when there is incorrect indentation.
20TabError #Raised when indentation consists of inconsistent tabs and spaces.
21SystemError #Raised when interpreter detects internal error.
22SystemExit #Raised by sys.exit() function.
23TypeError #Raised when a function or operation is applied to an object of incorrect type.
24UnboundLocalError #Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable.
25UnicodeError #Raised when a Unicode-related encoding or decoding error occurs.
26UnicodeEncodeError #Raised when a Unicode-related error occurs during encoding.
27UnicodeDecodeError #Raised when a Unicode-related error occurs during decoding.
28UnicodeTranslateError #Raised when a Unicode-related error occurs during translating.
29ValueError #Raised when a function gets argument of correct type but improper value.
30ZeroDivisionError #Raised when second operand of division or modulo operation is zero.
1# Raise is used to cause an error
2raise(Exception("Put whatever you want here!"))
3raise(TypeError)
1try:
2 print("I will try to print this line of code")
3except:
4 print("I will print this line of code if an error is encountered")
1try:
2 # Code to test / execute
3 print('Test')
4except (SyntaxError, IndexError) as E: # specific exceptions
5 # Code in case of SyntaxError for example
6 print('Synthax or index error !')
7except :
8 # Code for any other exception
9 print('Other error !')
10else:
11 # Code if no exception caught
12 print('No error')
13finally:
14 # Code executed after try block (success) or any exception (ie everytime)
15 print('Done')
16
17# This code is out of try / catch bloc
18print('Anything else')