forked from michaelliao/learn-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3b303e
commit 392e529
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# err_raise.py | ||
class FooError(ValueError): | ||
pass | ||
|
||
def foo(s): | ||
n = int(s) | ||
if n==0: | ||
raise FooError('invalid value: %s' % s) | ||
return 10 / n | ||
|
||
foo('0') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# err_reraise.py | ||
|
||
def foo(s): | ||
n = int(s) | ||
if n==0: | ||
raise ValueError('invalid value: %s' % s) | ||
return 10 / n | ||
|
||
def bar(): | ||
try: | ||
foo('0') | ||
except ValueError as e: | ||
print('ValueError!') | ||
raise | ||
|
||
bar() | ||
|