initial fluent-widgets ui
This commit is contained in:
31
qfluentwidgets/common/exception_handler.py
Normal file
31
qfluentwidgets/common/exception_handler.py
Normal file
@ -0,0 +1,31 @@
|
||||
# coding:utf-8
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
|
||||
def exceptionHandler(*default):
|
||||
""" decorator for exception handling
|
||||
|
||||
Parameters
|
||||
----------
|
||||
*default:
|
||||
the default value returned when an exception occurs
|
||||
"""
|
||||
|
||||
def outer(func):
|
||||
|
||||
def inner(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except BaseException as e:
|
||||
value = deepcopy(default)
|
||||
if len(value) == 0:
|
||||
return None
|
||||
elif len(value) == 1:
|
||||
return value[0]
|
||||
|
||||
return value
|
||||
|
||||
return inner
|
||||
|
||||
return outer
|
||||
Reference in New Issue
Block a user