- [Instructor] In some cases, you might find it necessary
to raise exceptions explicitly in your code.
For example, if you are defining your own functions that
are going to be part of a library that other people use,
you may want to indicate exceptions
when they use your library's functions incorrectly.
So to do that, Python provides the raise statement
and you simply follow the raise keyword by the name
of the exception class that you want to create an object of
and insert into the exception handling mechanism.
Now optionally, when you're creating that exception object,
you can supply parenthesis following the class name.
So for example, if you wanted to give a custom error message
for a particular exception instance that you're creating,
you would supply that as an argument in parenthesis
following the exception class name in your raise statement,
and by the way, before you raise an exception,
it's important that your code de-allocate any resources
that it acquired so those resources
are handed back to the system properly.
Now in general, you'll probably work with
one of the many built-in exception types.
You can find those at the URL
shown at the bottom of this slide,
but it is possible to create your own new exception types
as well which does require creating new class definitions.
That's part of what we'll be discussing in the next lesson.