-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.py
More file actions
33 lines (33 loc) · 868 Bytes
/
Copy pathdecorator.py
File metadata and controls
33 lines (33 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def except_wrapper(handler='default_handler'):
def exec_decorator(func):
hd = getattr(Handler, handler)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
hd(e)
return wrapper
return exec_decorator
class Handler(object):
def __init__(self):
pass
@staticmethod
def default_handler(e):
print "this is a default handler"
print e
@staticmethod
def simple_handler(e):
print "this is a simple handler"
print e
class API(object):
def __init__(self):
pass
@except_wrapper()
def test1(self):
raise Exception("test1 exception")
@except_wrapper('simple_handler')
def test2(self):
raise Exception("test2 excetpion")
api = API()
api.test1()
api.test2()