JK2
0
Q:

python: raise error

# Raise is used to cause an error
raise(Exception("Put whatever you want here!"))
raise(TypeError)
7
class MyError(TypeError):
    pass

raise MyError('An error happened')
0
	# this raises a "NameError"

>>> raise NameError('HiThere')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: HiThere
0
>>> 10 * (1/0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>> 4 + spam*3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'spam' is not defined
>>> '2' + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
-3

New to Communities?

Join the community