Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I find out the return value before returning while debugging in Eclipse?

People also ask

How can check variable value while debugging in Eclipse?

Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on.

How do I go back to previous Debug in Eclipse?

Open Debug Configuration -> Debugger -> Enable Reverse Debugging at startup . Than you can press shift+F5 or shift+F6 for step back like F5 or F6 for step forward.

How do I view Debug logs in Eclipse?

In your Eclipse development interface, select Window > Preferences. This mode displays verbose debug logs so you can view them in the Eclipse console window while you are previewing the app.

Can we go back in debugging?

Using the new Step Backward and Forward buttons So, if you've just taken a step in live debugging (F10 or F11), you can use the Step Backward button to quickly navigate to the previous step.


This feature was added to Eclipse version 4.7 M2 under Eclipse bug 40912.

To use it:

  • step over the return statement (using "Step Over" or "Step Return")
  • now the first line in the variable view will show the result of the return statement, as "[statement xxx] returned: "

See Eclipse Project Oxygen (4.7) M2 - New and Noteworthy for details.


Found a really good shortcut for this. Select the expression which returns the value and press

Ctrl + Shift + D

This will display the value of the return statement. This is really helpful in cases where you can't or don't want to change just for debugging purpose.

Hope this helps.

Note: Have not tested this with third party libraries, but it is working fine for my code. Tested this on Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 1


This is actually a long standing bug in Eclipse, dating back from the very first days of the IDE: https://bugs.eclipse.org/bugs/show_bug.cgi?id=40912


That's why I always stick with the following pattern for methods:

MyReturnedType foo() {
     MyReturnedType   result = null;

     // do your stuff, modify the result or not

     return result;
}

My rules:

  1. Only one return statement, only at the end of the method (finally allowed after it)
  2. Always have a local called result which holds the returned value, starting from a default.

Naturally, the most trivial getters are exempt.


I am curious about to learn the answer to this question also.

In the past, when dealing with 3rd party library like that, what I did is to create a wrapper class or child class that delegate to the parent class and do my debugging in the wrapper/child class. It takes extra work though.