Chapter 10 (error checking) Flashcards

1
Q

What is a syntax error?

A

Violating a programing languages rules on combinations of symbols and functions to create a program

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

Is a syntax error found as the code is run sequentially or before the program is run?

A

Before the program is run

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

How do you avoid errors in your code?

A

Frequently run it to make sure each new section of code works

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

What is a runtime error?

A

When syntax is correct but an impossible operation is attempted, like dividing by 0 or change a string to an int()

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

Are run time errors found during the sequential running of code or before the program is run?

A

Running the program, it results in a crash

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

What is a crash?

A

An unintentional termination of code

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

What is an indentation error?

A

When the code is not properly indented

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

What is a value error?

A

When an invalid value is given, like a string giving to an integer variable

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

What is a name error?

A

When the program tries to use a variable that does not exist

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

What is a type error?

A

When an operation does not work because of the data type,
- string / string

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

What is a logic error?

A

When the code isn’t incorrect but it runs incorrectly

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

what is an EOFError?

A

Input( ) hits an end-of-file (EOF) condition without reading anything. The input function has no input to read

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

What is a KeyError?

A

When a key isn’t found when reading a dictionary

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

What is a ZeroDivisionError?

A

divide by zero error

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

What is an Index Error?

A

Index out of range

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

What is the try-except function used for?

A

Testing for errors without crashing the program, the functions acts similarly to an if statement

17
Q

What is the format of a multistage try-except function?

A

try:
except (error type):
except:

18
Q

What is an IO error?

A

When a file cannot be opened
- (Input/output)

19
Q

What does raise do?

A

Allows code to identify an error and exit at try block while executing an instruction:
while True:
try:
raise ValueError(‘Invalid
number’)
except ValueError as excpt:
print(excpt)
# prints ‘invalid number’
num = int(input(‘enter a number’))

20
Q

How do you check for specific error?

A

for specific errors

except ErrorType:

except:
# catches all errors

21
Q

What happens if an error is checked during a function?

A

If the exception is not found within the function, the function will go back to the caller function to look for an exception

22
Q

A raise statement in a function causes the function to return a value before exiting (T/F)?

A

False, the function is exited immediately in search for an exception instruction

23
Q

What does the finally block do in a try-except block?

A

Runs after both the try and except blocks, a final block to print/ do something for both situations

24
Q

What is hierarchical debugging?

A

Taking sections of code to debug so it is easier to pin point where the mistake is

25
Q

What is visual debugging?

A

Looking for a bug without adding any code, just looking line by line to see if there are any errors
- if the error is not found the error hypothesis is inconclusive

26
Q

What does a try statement look like?

A

try:
—-code
except:
—-code that runs if try code is an error
except exception:
—-code runs for specified error
else:
—-code runs only if no error occurred
finally:
—-always run this

27
Q

How do you run a specific code if there is no error in a try statement?

A

try:
—-code
else:
—-code

28
Q

How do you always run code after a try statement, disregarding if there was an error or not?

A

try:
—-code
except:
—-code
finally:
—-code