class MyException(Exception):
def __str__(self):
return self.args[0]
def DoWork():
raise MyException("My hoverboard is full of eels")
pass
if __name__ == '__main__':
try:
DoWork()
except MyException as ex:
print("This will get printed: " + str(ex)) #Line1
print("This will not get printed and will raise exception: " + ex) #Line2
例外が1行目で明示的な変換を必要とするのはなぜですか。理想的には、2行目に示されているように機能するはずです。注:MyExceptionクラスからのstrの削除とstrの追加の両方を試しました。どちらも機能しませんでした。助けてください。