Skip to content

Instantly share code, notes, and snippets.

@01x01
Created January 31, 2019 12:35
Show Gist options
  • Save 01x01/93c6ecad722a92a735c722582962bb21 to your computer and use it in GitHub Desktop.
Save 01x01/93c6ecad722a92a735c722582962bb21 to your computer and use it in GitHub Desktop.
# 如何自定义异常类
class Error(Exception):
pass
class InputError(Error):
def __init__(self,message):
self.message = message
def __str__(self):
return self.message
def test_exception():
i = 1
if i == 1:
raise InputError("the number can't equal to 1")
try:
test_exception()
except InputError as e:
print(e)
# 如何记录异常堆栈
try:
excep_class.except_fun(excep_class)
except:
s=traceback.format_exc()
logging.error(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment