u05-slides-exceptions-debugging-flashcards

1
Q

What is an exception in Python?

A

An object created when an error occurs that carries information about what went wrong

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you raise an exception in Python?

A

Using the raise statement (e.g., raise ValueError(“message”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the main blocks in exception handling?

A

try (where code might raise exception), except (handles exceptions), finally (always executes), and else (executes if no exception)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some common predefined exceptions in Python?

A

TypeError, ValueError, IndexError, KeyError, ZeroDivisionError, FileNotFoundError, ModuleNotFoundError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are exceptions passed in Python?

A

Upwards through the calling hierarchy until caught or program fails

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when an exception is raised?

A

Program execution jumps to where the exception is caught or to the end of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you catch multiple exceptions at once?

A

Using parentheses in except statement (e.g., except (ValueError, TypeError, IndexError))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the purpose of the ‘as’ keyword in except blocks?

A

It allows you to access the exception object and its details

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the purpose of the finally block?

A

To execute code regardless of whether an exception occurred or not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the purpose of the else block in exception handling?

A

To execute code only if no exception occurred in the try block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is the order important in catching multiple exceptions?

A

The first matching except clause is executed so more specific exceptions should come before general ones

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can exception handling be nested?

A

Yes you can have try statements within except else and finally clauses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is debugging?

A

The process of identifying and removing errors from code during development

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a breakpoint?

A

A marker that pauses program execution at a specific line of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you set a breakpoint in VS Code?

A

By clicking in the gutter to the left of the line numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Step Over in debugging?

A

Executes current line and pauses at next line (F10 in VS Code)

17
Q

What is Step Into in debugging?

A

Moves into a function call to debug it line by line (F11 in VS Code)

18
Q

What is Step Out in debugging?

A

Completes current function and pauses after returning (Shift+F11 in VS Code)

19
Q

What is the Call Stack in debugging?

A

Shows the sequence of function calls that led to the current execution point

20
Q

What is a conditional breakpoint?

A

A breakpoint that only triggers when certain conditions are met

21
Q

What can you do in the Debug Console?

A

Execute code snippets in the context of the paused program

22
Q

How can you inspect variables while debugging?

A

Using the Variables pane or hovering over variables in the code

23
Q

Why is proper error handling important?

A

It can provide clear error information, terminate properly, or fix errors and continue execution

24
Q

What are logging breakpoints?

A

Breakpoints that write messages to the debug console instead of pausing execution

25
Q

How do you continue execution in debugging?

A

Using Continue (F5) to resume execution until the next breakpoint