How to use debug perspective in eclipse.[debugging java/j2ee applications]

前端 未结 2 1294
夕颜
夕颜 2021-01-25 12:10

Is there any easy to follow tutorial for debugging Java / J2EE applications in eclipse? A step by step guide on how to check for unchecked and checked exceptions? I have been tr

相关标签:
2条回答
  • 2021-01-25 12:49

    To add a Java Exception Breakpoint: Select the "Breakpoints" view in the Debug perspective and click on the view toolbar button for exception breakpoints (or choose Run->Add Java Exception Brekakpoint). In the next dialog, type the name of the exception (camel case is support, simply type NPE if you want to catch NullPointerExceptions, you'll get a list matching items), select it from the list and press OK. C'est ca.

    You can activate/deactivate this special breakpoint from the Breakpoints view like normal breakpoints.

    More fun: right click on a breakpoint entry in the Breakpoints view and choose "Breakpoint Properties". There you can add extra conditions, like 'only break when myCustomString.equals("WTF")' or something else. But conditional breakpoints will slow down the application significantly, only activate them if you really need them.

    0 讨论(0)
  • 2021-01-25 13:15

    The debugger in Eclipse will automatically suspend execution (and let you inspect variables/step/resume etc) if an uncaught exception is thrown.

    Enter for instance the following program...

    public class Test {
    
        public void methodA() {
            methodB("hello");
            methodB(null);
        }
    
        public void methodB(String s) {
            System.out.println(s.substring(2));
        }
    
        public static void main(String[] args) {
            new Test().methodA();
        }
    }
    

    ... and click the little "bug"-icon or choose Run -> Debug As -> Java Application

    enter image description here


    A few useful tutorials

    • Debugging a Java Program with Eclipse
    • Java Debugging with Eclipse - Tutorial
    0 讨论(0)
提交回复
热议问题