001 What-are-the-Exceptions
001 What-are-the-Exceptions
Welcome to our new section, “Dealing with Errors and Exception Handling in Python”.
With this section, you are going to learn how to handle the exceptions and how to solve the errors you get.
Let’s start with what an exception is. When Python encounters an error while running your code, it stops the execution of the
program and raises an exception.
An exception is an object with a description of what went wrong and a trace back where the problem occurred.
Let’s look at some of the common errors that you may encounter with while writing programs in Python:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-80189151beb8> in <module>()
----> 1 print(a) #Not defined! NameError
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-0af2fba1c044> in <module>()
----> 1 int("xsaw2345") # ValueError Exception
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-3-b9259676df39> in <module>()
----> 1 3 / 0 # Zero Division Error
If you want to see the list of all the errors anyway, you can look at it in the official website of Python.
https://docs.python.org/3/library/exceptions.html (https://docs.python.org/3/library/exceptions.html)
We are going to see how to catch errors and how to handle the errors that we encounter, in detail in our next lesson.