Chapter 10 (error checking) Flashcards
What is a syntax error?
Violating a programing languages rules on combinations of symbols and functions to create a program
Is a syntax error found as the code is run sequentially or before the program is run?
Before the program is run
How do you avoid errors in your code?
Frequently run it to make sure each new section of code works
What is a runtime error?
When syntax is correct but an impossible operation is attempted, like dividing by 0 or change a string to an int()
Are run time errors found during the sequential running of code or before the program is run?
Running the program, it results in a crash
What is a crash?
An unintentional termination of code
What is an indentation error?
When the code is not properly indented
What is a value error?
When an invalid value is given, like a string giving to an integer variable
What is a name error?
When the program tries to use a variable that does not exist
What is a type error?
When an operation does not work because of the data type,
- string / string
What is a logic error?
When the code isn’t incorrect but it runs incorrectly
what is an EOFError?
Input( ) hits an end-of-file (EOF) condition without reading anything. The input function has no input to read
What is a KeyError?
When a key isn’t found when reading a dictionary
What is a ZeroDivisionError?
divide by zero error
What is an Index Error?
Index out of range
What is the try-except function used for?
Testing for errors without crashing the program, the functions acts similarly to an if statement
What is the format of a multistage try-except function?
try:
except (error type):
except:
What is an IO error?
When a file cannot be opened
- (Input/output)
What does raise do?
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’))
How do you check for specific error?
for specific errors
except ErrorType:
except:
# catches all errors
What happens if an error is checked during a function?
If the exception is not found within the function, the function will go back to the caller function to look for an exception
A raise statement in a function causes the function to return a value before exiting (T/F)?
False, the function is exited immediately in search for an exception instruction
What does the finally block do in a try-except block?
Runs after both the try and except blocks, a final block to print/ do something for both situations
What is hierarchical debugging?
Taking sections of code to debug so it is easier to pin point where the mistake is
What is visual debugging?
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
What does a try statement look like?
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
How do you run a specific code if there is no error in a try statement?
try:
—-code
else:
—-code
How do you always run code after a try statement, disregarding if there was an error or not?
try:
—-code
except:
—-code
finally:
—-code