File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments