python: How do I know what type of exception occurred?

后端 未结 15 2127
情书的邮戳
情书的邮戳 2020-11-29 14:56

I have a function called by the main program:

try:
    someFunction()
except:
    print \"exception happened!\"

but in the middle of the ex

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 15:12

    You can start as Lauritz recommended, with:

    except Exception as ex:
    

    and then just to print ex like so:

    try:
        #your try code here
    except Exception as ex:
        print ex
    

提交回复
热议问题