Altering the program's execution flow
Return to a previous stack frame
IntelliJ IDEA lets you fall back to a previous stack frame in a program's execution flow. This can be useful, for example, if you've mistakenly stepped too far, or want to re-enter a function where you missed a critical spot.
- Click the Drop Frame icon in the Debugger tool window toolbar:
Force return from the current method
You can force the return from the current method before the return statement is reached and without executing any more instructions from it.
- Select the Force Return action from the context menu of the current method in the Frames view, or press Ctrl+Shift+A:
- If the method returns a value, you'll need to specify it. If the method has try-finally blocks, you will be prompted to choose whether you want to execute them.
Throw an exception
IntelliJ IDEA lets you throw an exception from a certain location in your program without modifying the code.
- Select Throw Exception from the context menu of the selected method in the Frames view and specify the expression:
Reload modified classes
Sometimes, when you're making minor changes to your code, you want to immediately see how they will behave in a working application without shutting down the process. The HotSwap mechanism lets you reload classes changed during a debugging session without having to restart the entire application.
Recompile the modified class
- From the main menu choose Build | Compile <class_name>.
If you want to disable automatic reloading of changed classes after their compilation, in the Settings/Preferences dialog (Ctrl+Alt+S) choose Build, Execution, Deployment | Debugger | HotSwap in the left pane, and set the Reload classes after compilation option to Never. Then, if you want to reload a modified class, you will need to choose Run | Reload Changed Classes after you've recompiled it.