An unavoidable part of being a programmer is that your programs are going to give a lot of errors,
you can't avoid bugs, you can't avoid programs breaking.
A simple print function here with, let's say, a misspelled word with let's say no comma, if I run
this, we've been seeing this a lot, right?
We've been seeing a lot of this red throughout this course, a lot of these errors.
If I tried to add one plus let's say.
That works, but then all of a sudden I decide to add hello to one.
And yet again, we see that red this time a type ER.
That crashes our program like this is called an exception.
And Python.
Raises these exceptions whenever the interpreter says, hey, I have no idea what you're doing, something's
wrong, I don't know what I'm doing anymore, I'm going to stop whatever I'm doing and I'm going to
give you an output.
This is bad because right now we're just playing, but if we're Google and people depend on us to maybe
check their email, to watch YouTube videos, if our programs have exceptions and they stop working
and they eera out, that's bad.
That could cost companies millions.
So how can we handle these exceptions that crash our program?
Well, we need something called air handling.
It's a natural part of being a programmer and a great programmer is able to handle errors in their program.
Because instead of letting our programs just air, we're able to handle them so that if we get something
like a type like this, we can actually handle that air within our programs.
And in this section, we're going to learn all about that.
But the key takeaway is that air handling allows us to let the Python script continue running, even
if there are errors.
Sounds pretty interesting, right?
Well, before we get into that, let's just talk about some of the errors that exist in Python.
We've already seen type error.
Where are we trying to do something between two different data types that are incompatible, such as
adding ENT and string and these built-In exceptions in Python?
There's lots of them.
And I'll link to this resource so you can take a look.
But if I scroll through here, you see attribute, error and of failure, we keep going.
We have a name error.
We have so many error reference.
There's just a ton.
Let me just go through some of them that are quite common.
One is a syntax error if I do def and let's say.
Whoo hoo!
And I forget a semicolon here and I run this.
I get a syntax error, it's not a standard python syntax, I have to fix my error.
I can also get something called a Namir if let's say I use one plus name like this and I click.
Name like this, you can see the red underline here, I get undefined name so that if I run this code.
I'll get a nightmare name is not defined.
We've seen type ER.
But what about this, what have we have a list, let's say Elai.
One, two, three, and I access Elai, let's say an index of five if I run this.
I get an index error list index is out of range.
What if we had a dictionary, so let's say we're creating a dictionary here.
We'll say a.
Cause one and, you know, I will just leave it at that.
So this will be a dictionary.
If I do dictionary here and just try to access something that doesn't exist and I click run.
I get a key error.
Because I'm accessing a key that doesn't exist.
We can also have, let's say, five divided by zero, which should give me a zero division error because
I'm trying to divide by zero and well, you just can't do that.
So there's lots of errors or built-In exceptions in Python.
Now, you don't have to memorize any of these.
Most of the time they'll come up in your program and you'll know what they mean.
But you can always use this as a reference to read them.
The question you should be asking yourself is, how do we avoid these?
Because most programs aren't just us typing information, usually programs interact with the outside
world.
Right when I log into my email, I let a user use their email and password.
When I play a game, I let a user control a character.
So programs are constantly interacting with the outside world and they have to make sure that whatever
input they get is the right type that they're expecting.
Because if they receive something that they didn't expect like number and this number just happens to
be, let's say, zero, that we give it.
Well, this user broke our program, so we need to handle these situations where a user might give something
bad that we wouldn't want.
In the next video, we're going to explore how we can handle our errors.