-: So we've just created a program
that isn't going to error out, hopefully
at least with value errors and zero division errors.
But sometimes errors and exceptions can be so severe
that we do want to stop our programs from running.
We do wanna catch them like this with the except block, but
at the same time also stop whatever the program is doing.
Maybe instead of print, we actually wanna display
that red here and says,
"Oh, something bad's happening. Stop that."
Well, in that case, we either don't use the except block
or in here we can say, raise ValueError.
Now, this is rare that you'd have to do this.
There are some specific use cases,
but here you would just write a message saying,
" Hey cut it out",
so that if I run this,
well if I type in a valid number,
again, please enter a number.
Okay, I'm finally done because I raise a value error
and it throws in here into the except block.
So I'd have to remove this.
And if I remove this like this and hit run
enter five and look at that, I get a value error.
"Hey, cut it out."
So I'm able to throw my own errors.
So this is really useful,
if you're creating your own library or tool
and you wanna let the user know that an error happened
"I'm not gonna keep doing what you're doing."
And this could be any type of error.
You can also do something like exception
and if I click run here, do five
I get an exception, "Hey, cut it out."
The key thing to remember with errors
is that errors are unavoidable in programming.
What your job is as a programmer is to be able to
anticipate these errors, these bugs, these exceptions
and handle them properly in your programs.
And some of the biggest errors happen when
we're trying to accept input from a user
not just using this input
but functions, accepting arguments,
classes accepting different inputs from users
like method calls and trying to change attributes.
When the outside world and our programs
try to communicate with each other,
errors are bound to happen.
Our job as programmers is to try and code
in a way that handles these exceptions gracefully
and we can anticipate these errors.
There's no such thing as a perfect program.
However, we can try and do our best
to learn from these errors
and try to manage them so that our programs don't break.
I'll see you on the next one.
Bye-bye.