Error & Exception Handling Flashcards

1
Q

break (def + ex.)

continue (def + ex.)

pass (def + ex.)

try / except pass

A

utilized within loops for additional functionality

( 1 )

break: breaks out of the closest enclosing loop

n_string = “sammy”

for letter in n_string:

if letter == ‘a’ :

break

print ( letter )

returns only s then stops running

( 2 )

continue: goes to the top of the closest enclosing loop

n_string = “sammy”

for letter in n_string:

if letter == ‘a’ :

continue

print ( letter )

returns all letters except a in sammy

( 3 )

pass: does nothing, used to create empty functions for later use

( 4 )

try / except pass: skips to the next iteration

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

Error & Exception Handling Purpose

&

Statement Componenets

(4)

(not all have to be used)

&

Example

A

Purpose:

allows the script to continue if a user or another programmer executes the code in an unintended way raising an error or exception, used as a wrapper for statements

Statement Components:

try: the attempted block of code

except: block of code allowing executing if an error occurs

else: if no error or execption occurs execute this statement

finally: block of code to be executed, regardless of an error

Example:

def divide(x,y):

try:

result = x // y # floor division

except:

print(“Sorry ! You are dividing by zero”)

finally:

print(“Code that will always execute”)

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

EOL (end of line)

A

syntax error: interpreter expected a character at the end of a string literal, but one was not found

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

EOF (end of file)

A

syntax error: a function hits the end of the file without reading data

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

Leading Zero Error

A

leading zeros are not allowed for integer literals, because of ambiguity. They are are used for hex (0x), octals (0o), and binaries (0b).

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

Syntax Error

A

error referring to the structure of the script ex. non closed parenthesis

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

Runtime Error or Exceptions

A

defects that manifest only at runtime an interruption that occurs at runtime, forcing the program to stop execution

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

Semantic Error

A

statement is syntactically valid, but the code does not do what the programmer intended

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

Type Error

A

raised when operation or function is applied to an object of inappropriate type (adding a string and integer together)

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

OSError

(Definition)

A

class of built in errors that are invoked when a system related error occurs

there are 15 subclasses of errors that can be invoked depending on the specific error raised (look to python documentation for the list)

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