Exceptions are commonly used for error reporting in Python. Python uses the try and except statements for catching exception errors.
- [Instructor] Exceptions are a powerful…runtime error reporting mechanism…commonly used in object-oriented systems.…Here in Komodo, I've opened a working copy of hello.py…from Chapter 10 of the exercise files,…and what I'd like to do here is just generate an error.…We'll say "x =…int of" and we'll give it a string,…and so that's an error, and when I run this,…you see we get this error message down here.…Just expand this a little bit,…and there's a lot of stuff here.…
At the very bottom, you'll see it says "ValueError:…invalid literal for int() with base 10: 'foo.'"…That's our actual error message.…Everything else is what's called traceback,…and you can see it says "Traceback,"…and it goes bottom to top.…The actual line with the error is on line 5,…and you see that my cursor appears on line 5,…and that's where the error is.…Line 7…is where that is called from,…and so down here on line 7…is the main call,…which calls the function that has the error.…
This traceback, under some circumstances,…could help you to trace where the error is…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.