Lecture 3 - Exception Flashcards

1
Q

Exceptions that require you to double-check that you typed in your code correct.

A

Syntax Errors

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

Exceptions created by unexpected behavior within your code.

A

Runtime Errors

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

Is an exception that occurs when a function receives an argument of the correct data type but an inappropriate value

A

ValueError

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

This block lets you test a block of code for errors.

A

Try

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

This block lets you handle the error.

A

Except

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

This block lets you execute code when there is no error.

A

Else

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

This block lets you execute code, regardless of the result of the try- and except blocks.

A

Finally

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

This exception is raised when the program attempts to access or use a variable that has not been defined or assigned a value.

A

NameError

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

This will let you break out of a loop, but it will also return a value.

A

Return

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

This statement is used as a placeholder for future code. When executed, nothing happens, but you avoid getting an error when empty code is not allowed.

A

Pass

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

Try & Except Syntax

A

try:
x = int(input(“What’s x?”))
print(f”x is {x}”)
except ValueError:
print(“x is not an integer”)

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

This keyword is used to break out a for loop, or a while loop.

A

Break

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

Break & Else Syntax

A

while True:
try:
x = int(input(“What’s x?”))
except ValueError:
print(“x is not an integer”)
else:
break

print(f”x is {x}”)

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

Return Syntax

A

def get_int():
while True:
try:
x = int(input(“What’s x?”))
except ValueError:
print(“x is not an integer”)
else:
return x

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

Pass Syntax

A

def get_int():
while True:
try:
return int(input(“What’s x?”))
except ValueError:
pass

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