u05-slides-exceptions-debugging-flashcards
What is an exception in Python?
An object created when an error occurs that carries information about what went wrong
How do you raise an exception in Python?
Using the raise statement (e.g., raise ValueError(“message”))
What are the main blocks in exception handling?
try (where code might raise exception), except (handles exceptions), finally (always executes), and else (executes if no exception)
What are some common predefined exceptions in Python?
TypeError, ValueError, IndexError, KeyError, ZeroDivisionError, FileNotFoundError, ModuleNotFoundError
How are exceptions passed in Python?
Upwards through the calling hierarchy until caught or program fails
What happens when an exception is raised?
Program execution jumps to where the exception is caught or to the end of the program
How do you catch multiple exceptions at once?
Using parentheses in except statement (e.g., except (ValueError, TypeError, IndexError))
What’s the purpose of the ‘as’ keyword in except blocks?
It allows you to access the exception object and its details
What’s the purpose of the finally block?
To execute code regardless of whether an exception occurred or not
What’s the purpose of the else block in exception handling?
To execute code only if no exception occurred in the try block
Why is the order important in catching multiple exceptions?
The first matching except clause is executed so more specific exceptions should come before general ones
Can exception handling be nested?
Yes you can have try statements within except else and finally clauses
What is debugging?
The process of identifying and removing errors from code during development
What is a breakpoint?
A marker that pauses program execution at a specific line of code
How do you set a breakpoint in VS Code?
By clicking in the gutter to the left of the line numbers
What is Step Over in debugging?
Executes current line and pauses at next line (F10 in VS Code)
What is Step Into in debugging?
Moves into a function call to debug it line by line (F11 in VS Code)
What is Step Out in debugging?
Completes current function and pauses after returning (Shift+F11 in VS Code)
What is the Call Stack in debugging?
Shows the sequence of function calls that led to the current execution point
What is a conditional breakpoint?
A breakpoint that only triggers when certain conditions are met
What can you do in the Debug Console?
Execute code snippets in the context of the paused program
How can you inspect variables while debugging?
Using the Variables pane or hovering over variables in the code
Why is proper error handling important?
It can provide clear error information, terminate properly, or fix errors and continue execution
What are logging breakpoints?
Breakpoints that write messages to the debug console instead of pausing execution
How do you continue execution in debugging?
Using Continue (F5) to resume execution until the next breakpoint