在可以或可以不與一個debug
參數運行CLI應用,我捕獲異常並選擇性地重新拋出它:爲什麼Exception(str())拋出異常?
try:
doSomething()
except Exception as e:
if debug==True:
raise Exception(str(e))
有趣的是,raise Exception()
代碼本身引發此:
Traceback (most recent call last):
File "./app.py", line 570, in getSomething
raise Exception(str(e))
Exception: expected string or buffer
會不會str(e)
返回一個字符串?我只能想象它可能正在返回None
,所以我嘗試了一般的Exception
(如代碼所示),希望它永遠不會成爲無。爲什麼e
不能澆注到string
?
'str(e)=='預期的字符串或緩衝區'。你的代碼工作正常。 – Volatility