Skip to content

Commit d4b3d45

Browse files
committed
added soluiton to the break_me problem.
1 parent 4e03f78 commit d4b3d45

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Solutions/Session01/break_me.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
A simple set of examples that raise various Exceptions
5+
"""
6+
7+
8+
def name_error():
9+
"""This function raises a NameError"""
10+
# very easy to do -- simply try to use a name you haven't defined
11+
x = something
12+
13+
14+
def type_error():
15+
"""This function raises a TypeError"""
16+
# Try to use an object in a way that doesn't make sense
17+
"543" / 3
18+
19+
def attribute_error():
20+
"""This function raises an AttributeError"""
21+
x = 5
22+
y = x.strip()
23+
24+
# have to comment this out, because the SyntaxError keeps the code from
25+
# running at all
26+
# def syntax_error():
27+
# """This function raises a SyntaxError"""
28+
# del = 32 # this one is tricky -- it's an error because "del" is a keyword
29+
30+
# now run the functions:
31+
# Note: I have all but one commented out, becaue the code stops running
32+
# when the first Error is hit.
33+
34+
# name_error()
35+
# type_error()
36+
attribute_error()

0 commit comments

Comments
 (0)