try:
raise RuntimeError(["abc"])
except RuntimeError as error:
print(error, type(error))
print(error[0])
['abc'] <class 'RuntimeError'>
TypeError: 'RuntimeError' object is not subscriptable
1
optional 2020-02-03 19:57:39 +08:00
继承
|
2
1462326016 2020-02-03 20:08:54 +08:00
一楼正解
```Python class CustomizeError(BaseException): def __init__(self, data): self.data = data super(CustomizeError, self).__init__() def __data__(self): return self.data try: raise CustomizeError([]) except CustomizeError as e: print(e.data, type(e.data)) ``` |
3
1462326016 2020-02-03 20:10:45 +08:00
这么写就可以,上边的错误类写多了
不知道回复里怎么用 markdown ```python class CustomizeError(BaseException): def __init__(self, data): self.data = data super(CustomizeError, self).__init__() try: raise CustomizeError([11, 2, 3, 3, 4222]) except CustomizeError as e: print(e.data, type(e.data)) ``` |
4
lasuar 2020-02-03 20:26:28 +08:00
error.args[0]
|