Created
January 31, 2019 12:35
-
-
Save 01x01/93c6ecad722a92a735c722582962bb21 to your computer and use it in GitHub Desktop.
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
# 如何自定义异常类 | |
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) |
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
# 如何记录异常堆栈 | |
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