- [Instructor] Before we get into actually
dealing with exceptions that occur at run time,
let's revisit the concept of an exception for a moment.
So first, for example, let's try division by zero
which we demonstrated in an earlier lesson.
As you can see here, we get a zero division error
indicating that division by zero occurred.
Now what you're looking at once here is a trace back
and it's telling you information about not only the type
of problem that occurred, but where it occurred
in your code.
The code that was executing when the exception happened
terminates and in the context of a IPtyhon session
like this one you simply get the next In prompt
so that you can continue your interactive session,
but if this were in a script, the script would presumably
terminate at this point because we don't have any code
that says what to do if a zero division error occurs.
In another case that we saw previously
where an exception occurred, for example,
if I'm doing user input and I prompt the user to enter
an integer and then the user types something
and that value gets returned by the input function
let's assume that again we wanted an integer,
but the user types something that's not an integer
like hello in that case we get a value error.
And again it points out the snippet in which
the problem occurred, gives me an error message
with a little bit of more information as well.
In particular the value hello could not be turned
into an integer with base 10.
So these are a couple of examples of basic exceptions
that can be encountered when you're dealing
with file processing, network connections,
database processing, they're tend to be
many more possibilities for exceptions to occur
and depending on what it is you're doing
you may or may not need more robust code
to deal with those problems as they occur.
If you're simply in an interactive session like this one
you might not need to deal with a problem you may simply
execute a new snippet, but if you're dealing with a script
that perhaps performs a larger task you might want
some more robust code in there.
And that's what we're going to start looking at
in the next example.