-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_exception.py
55 lines (41 loc) · 1.32 KB
/
my_exception.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# encoding: utf-8
# @author: hoojo
# @email: hoojo_@126.com
# @github: https://github.com/hooj0
# @create date: 2018-03-20 22:03:33
# @copyright by hoojo@2018
# @changelog Added python3 `exception -> my exception` example
class Error(Exception):
'''base excption module'''
pass
class InputError(Error):
'''
input error extends Error exception module
Attribute:
exception 异常信息
message 自定义信息
'''
def __init__(self, exception, message):
self.exception = exception
self.message = message
class OutputError(Error):
'''
output exception extends Error exception module
Attribute:
prev 前一个输出内容
next 下一个输出内容
message 消息内容
'''
def __init__(self, prev, next, message):
self.prev = prev
self.next = next
self.message = message
try:
raise InputError('input error code', 'raise input exception!')
except InputError as e:
print('捕获到异常:', e.exception, ',消息:', e.message)
try:
raise OutputError('first message', 'current message', 'output exception!')
except OutputError as e:
print('prve:', e.prev, ', next: ', e.next, ', exception: ', e.message)