Throw Exception allows you to throw an exception from the current line of code during a debugging session. Any code after the line where you forced the return will not be executed. Once you apply Force Return, the debugger will terminate the current method immediately and return the specified value. A dialog will then appear where you can enter the desired value. Select the current method in the Frames tab, right-click anywhere in the tab, and choose Force Return. You do this with the Force Return action. With IntelliJ IDEA’s debugger, you can make methods return any value you want and test how the program works with them, without having to reproduce the conditions that lead to these values. Here are some less conventional actions for navigating your code and testing specific scenarios while debugging. Keep in mind that this step is available only for the top frame. To perform this action, hover over the frame you want to reset and then click the Reset Frame button that appears. Note that if changes are made to the global state, the IDE doesn’t revert them. This action brings you to the point right before the method call and resets the frame’s local variables that you’d changed inside it. Imagine you’ve stepped through the whole method and now find yourself at the end, but you feel like you’ve missed something important. To try this action out, press ⌥ F9 (macOS) or Alt+F9 (Windows or Linux). It allows the program to continue its execution until it reaches the caret, which can be in another method or even a different file. If you don’t want to run line-by-line code analysis and need to jump to a line that is far away, Run to Cursor is the stepping action for you. When you’ve finished examining a method you stepped into, you can get out of it with the help of the Step Out action, which you can invoke by clicking the up arrow in the tool pane of the Debug tool window or by pressing ⇧ F8 (macOS) or Shift+F8 (Windows or Linux). You can configure the IDE’s behavior for such cases in Preferences/Settings | Build, Execution, Deployment | Debugger | Stepping. There may be methods you want to avoid stepping into. Alternatively, it is possible to simply click on the method. You can move along the code with the help of keyboard arrows or the Tab key and press Enter when the desired method is framed. You will see that rectangles appear around the method calls. IntelliJ IDEA allows you to step into any method on the line with an action called Smart Step Into that will automatically be performed when Step Into (F7) is executed on the line with several method calls. If one line of code contains several method calls, you don’t need to enter them one at a time until you reach the one you are interested in. To try it out, click the second arrow in the top pane of the Debug tool window or press F7. If you encounter a method along the way and think it might be a good idea to enter it and check its execution, you can use the Step Into action. To do so, click the first of the arrow buttons in the Debug tool window or simply press F8. Let’s step over the lines in our file and see how the variable values appear in this pane. With it, you can analyze your code line by line and then see the results in the Variables pane of the Debug tool window. This is the most straightforward step, as it lets you jump to the next line of code without stepping into any methods. These actions allow you to step line by line through the code to inspect it. When you are ready, you will see that the basic stepping actions, which are displayed as arrows, become active in the top pane of the Debug tool window. To start stepping, you must either pause an ongoing debugging session or let the program stop at a breakpoint. We’ll explore how basic and advanced stepping actions help you use the IntelliJ IDEA debugger more efficiently. Our topic for this post is stepping, an invaluable procedure that allows you to move along your code to analyze it and find problems. In the upcoming articles, we’ll describe its core functionality as well as features designed for peculiar use cases. This Debugger Upskill blog post is the first in a series devoted to the IntelliJ IDEA debugger.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |