How do I enable post mortem debugging in pydev?

后端 未结 2 2076
无人及你
无人及你 2021-02-10 10:39

I want to make pydev enter into an interactive console mode whenever my program raises an unhandled exception but I can\'t figure out how to do it. As it behaves now, the except

2条回答
  •  爱一瞬间的悲伤
    2021-02-10 11:01

    Ok, so after a while I figured out the obvious, the code should be:

    import pydevd
    pydevd.GetGlobalDebugger().setExceptHook(Exception, True, False)
    

    To capture any unhadled exceptions. The method can be used in other ways to enter debug mode when the program crashes, as documented in the doc of setExceptHook:

    Should be called to set the exceptions to be handled and whether it should break on uncaught and caught exceptions.

    Can receive a parameter to stop only on some exceptions.

        E.g.:
            set_pm_excepthook((IndexError, ValueError), True, True)
    
            or
    
            set_pm_excepthook(IndexError, True, False)
    
            if passed without a parameter, will break on any exception
    
        @param handle_exceptions: exception or tuple(exceptions)
            The exceptions that should be handled.
    
        @param break_on_uncaught bool
            Whether it should break on uncaught exceptions.
    
        @param break_on_caught: bool
            Whether it should break on caught exceptions.
    

    I hope this'll help others who wants to use the pydev debugger in eclipse for debugging a program after an exception has been raised.

提交回复
热议问题