Skip to content

Commit

Permalink
add err raise, re-raise sample
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelliao committed May 18, 2015
1 parent b3b303e commit 392e529
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions samples/debug/err_raise.py
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')

17 changes: 17 additions & 0 deletions samples/debug/err_reraise.py
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()

0 comments on commit 392e529

Please sign in to comment.