0% found this document useful (0 votes)
4 views2 pages

001 What-are-the-Exceptions

What are the Exceptions?

Uploaded by

m.a.abrache
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

001 What-are-the-Exceptions

What are the Exceptions?

Uploaded by

m.a.abrache
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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:

In [1]: print(a) #Not defined! NameError

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-80189151beb8> in <module>()
----> 1 print(a) #Not defined! NameError

NameError: name 'a' is not defined

In [2]: int("xsaw2345") # ValueError Exception

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-0af2fba1c044> in <module>()
----> 1 int("xsaw2345") # ValueError Exception

ValueError: invalid literal for int() with base 10: 'xsaw2345'

In [3]: 3 / 0 # Zero Division Error

---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-3-b9259676df39> in <module>()
----> 1 3 / 0 # Zero Division Error

ZeroDivisionError: division by zero

In [5]: for i in range(10) #missing ":" character. #Invalid Syntax


print(i)

File "<ipython-input-5-7c49a140499e>", line 1


for i in range(10) #missing ":" character. #Invalid Syntax
^
SyntaxError: invalid syntax

The Complete Python 3 Programming Bootcamp: (Beginner to Advanced)


Like these ones, there are many more error types in Python. You don’t need to memorize all of these errors because, as I
said, actually there are numerous errors in Python. And this is really not necessary. This is exactly why we see how to handle
all these errors and exceptions in detail.

If you want to see the list of all the errors anyway, you can look at it in the official website of Python.

Let’s click on this link;

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.

So, this is the end of this lesson.

See you in our next lessons.

The Complete Python 3 Programming Bootcamp: (Beginner to Advanced)

You might also like