Exceptions - feilhåndtering

In [3]:
a = 12
print(a)
12
In [4]:
12/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-4-898e9759c56e> in <module>
----> 1 12/0

ZeroDivisionError: division by zero
In [5]:
12//0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-5-08dac9a1ba3c> in <module>
----> 1 12//0

ZeroDivisionError: integer division or modulo by zero
In [6]:
12%0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-6-891183f0e6a8> in <module>
----> 1 12%0

ZeroDivisionError: integer division or modulo by zero
In [8]:
b = 12

try:
    print(b)
except:
    print("Variabelen a er ikke definert")
12
In [9]:
L = [1,2,3,4,5,6,7,8,9,0]

L[11]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-6ac96e2278d6> in <module>
      1 L = [1,2,3,4,5,6,7,8,9,0]
      2 
----> 3 L[11]

IndexError: list index out of range
In [ ]:
 
In [10]:
print('12' + 3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-c3285e742fd4> in <module>
----> 1 print('12' + 3)

TypeError: must be str, not int
In [ ]: