> Nina Zakharenko: Just a quick thing about this KeyboardInterrupt error.
It'll generate a keyboard error, and it'll quit your program while it's running. > Nina Zakharenko: For programs that you run on the command line, if it's taking a really long time, we've been writing pretty fast scripts, and you wanna exist out of it, you can hit Ctrl+C. And in this case, it generates a KeyboardInterrupt error. If I'm typing something and I'm like, I made a mistake, I don't wanna hit Enter and get a syntax error. > Nina Zakharenko: You've seen me hit maybe Ctrl+C. So for those of you who have been seeing me use use the REPL, And this KeyboardInterrupt error, that's an interesting one.
PYTHON FASTSCRIPTS CODE
IndentationError, if you're messing with the level of indentation for if statements, classes, etc, functions, where you need to have your first line of code indented one level. Syntaćrror, the parser just doesn't even know what to do with your file. KeyError, we've seen this one, if a key was not in our dictionary. ImportError, if I try to import something that wasn't found. AttributeError, if I tried to use a attribute name that wasn't on my instance, I would get this error. So some common types of exceptions that you might see, there are a few more in the Python documentation, but very quickly.
PYTHON FASTSCRIPTS HOW TO
And that's not very good, right? But once you learn a little bit more about these exceptions and about how to handle them, it'll help you write apps that are a lot more robust in the face of issues. Or if you're using a web server, your end user will see a 500 error. Just take down your website, depending on kind of what you're seeing. So for production code, having uncaught exceptions is pretty bad, right? > Nina Zakharenko: And it'll stop your interpreter. It's gonna print out a traceback and then quit your code wherever it was at that time. Unhandled exceptions are fatal to your program. So even if your syntax is 100% correct, your program can still have exceptions.
For example, if you tried to run our final exercise from introduction to Python and you didn't have a valid internet connection, it would just raise an exception that we didn't catch and exit the program. > Nina Zakharenko: Even if the syntax is totally correct, sometimes errors occur when your program is run. If we get a value error, that means that something is wrong with the input that we gave, right? > Nina Zakharenko: If we get an indentation error, we know that we didn't indent our code properly. Those syntax errors that we've seen, they do a pretty good job of telling us what went wrong, right? > Nina Zakharenko: The built-in exceptions and exception handling, it's a really nice feature of Python. So I'm gonna tell you a little bit about the exception of hierarchy, about raising exceptions, and about how do you use try catch, and how to create our own custom exception process. But that's not enough in the course of a more complex program. We saw some simple try excepts yesterday.
But we haven't really figured out what to do about them. We've seen type error, syntax error, value error, indentation error. We've seen exceptions quite a bit over the course of this class. > Nina Zakharenko: Let's talk about exceptions. Transcript from the "Exception Types" Lesson