コード
print("---------------------------------------")
try:
raise Exception('aaaa')
except Exception as err:
print("type : ",type(err))
print("args : ",err.args)
print("self : ",err)
print("---------------------------------------")
try:
a = 1
b = "1"
print(a+b)
except Exception as err:
print("type : ",type(err))
print("args : ",err.args)
print("self : ",err)
print("---------------------------------------")
import traceback
try:
a = 1
b = "1"
print(a+b)
except:
err = traceback.format_exc()
print(err)
print("---------------------------------------")
結果
type : <class 'Exception'>
args : ('aaaa',)
self : aaaa
type : <class 'TypeError'>
args : ("unsupported operand type(s) for +: 'int' and 'str'",)
self : unsupported operand type(s) for +: 'int' and 'str'
Traceback (most recent call last):
File "x:/14_git/workflow/_Board/test1.py", line 25, in <module>
print(a+b) TypeError: unsupported operand type(s) for +: 'int' and 'str'