我正在尝试显示用户友好的错误消息,同时还显示异常,但我似乎无法使其正常工作。
我尝试了这些,但是语法无效:
#First try:
except Exception as e, ValueError:
print("\nThe program is unable to calculate the given equation. " +
"Try Again!")
print("\nError message " + e)
continue
#Second try:
except ValueError, Exception as e:
print("\nThe program is unable to calculate the given equation. " +
"Try Again!")
print("\nError message " + e)
continue
如果有人可以帮助我,那就太好了。谢谢!
答案 0 :(得分:0)
您可以使用追溯:
import traceback
#First try:
except ValueError:
print("\nThe program is unable to calculate the given equation. " +
"Try Again!")
print("\nError message " + traceback.format_exc())
continue
#Second try:
except Exception as e:
print("\nThe program is unable to calculate the given equation. " +
"Try Again!")
print("\nError message " + traceback.format_exc())
continue