How do I enable post mortem debugging in pydev?

后端 未结 2 2074
无人及你
无人及你 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.

    0 讨论(0)
  • 2021-02-10 11:06

    Actually, you don't need to do this programmatically... you can go to the Debug perspective > Pydev menu > Manage Exception Breakpoints

    and check 'Suspend on uncaught exceptions'. In most cases you will want to catch all kinds of exceptions (so choose "Select All") but you can also select exceptions to be managed individually.

    0 讨论(0)
提交回复
热议问题