

It is only available if a method body is modified. HotSwap limitationsĭue to VM design, HotSwap has the following limitations: If this option is disabled, you need to recompile the files before reloading ( Build | Recompile Control+Shift+F9). Recompilation happens automatically if the Build project before reloading classes option is enabled in Settings | Build, Execution, Deployment | Debugger | HotSwap. Go to Run | Debugging Actions | Reload Changed Classes. Automatic reloading can be enabled/disabled, or you can configure it so that the debugger asks you whether to reload the file in each specific case. You can also configure automatic reloading of classes after they have been recompiled using the Reload classes after compilation option in Settings | Build, Execution, Deployment | Debugger | HotSwap. Right-click in the editor tab of the modified file and select Compile and Reload File. The HotSwap mechanism lets you reload classes changed during a debugging session without having to restart the entire application. Sometimes, when you're making changes to your code, you want to immediately see how they will behave in a working application without shutting down the process. Make sure the current method is selected on the Frames tab, then right-click anywhere in the tab and select Throw Exception.Ĭreate the exception (this can be any Throwable including Error and checked exceptions that are not handled by the method).

This is useful when you want to test how a particular type of exception is handled in your program without having to reproduce the cause or modify the code. IntelliJ IDEA lets you throw an exception or error from the currently executed method.
#INTELLIJ IDEA DEBUG CODE#
If the execution point is currently in a try, catch, or finally block and there are lines of code in finally that have not been executed, select whether you want to skip them. The return value must conform to the method's return type. If the method returns a value (its return type is not void), specify the value or an expression that will calculate it.Įxpressions are evaluated in the local context and can use any local variables that have already been declared. Make sure the current method is selected on the Frames tab, then right-click anywhere in the tab and select Force Return. When you use Force return, the instructions after the current execution point are disregarded. Force return helps you test how the return values are handled by the program without having to reproduce the conditions that lead to these values. This is useful when the problem is related to the return value of the method and not to how it's produced. You can exit a method before it reaches the return statement and make it return an arbitrary value. In the properties of the new breakpoint, clear the Suspend checkbox and enter the expression that will modify the program state in the Evaluate and log field. If (addDebugLogic) new Debug().doSomething() Īdd a breakpoint at the line where you want to modify the program state. This is useful, for example, when you want to automatically modify your variables during debugging. In order to change the flow of your program, you can use non-suspending breakpoints that evaluate an expression when hit. Note that changes that were already made to the global state are not reverted, and only local variables are reset. Hover over the frame you want to reset, then click the Reset Frame button that appears. This can be useful, for example, if you've mistakenly stepped too far, or want to re-enter a method where you missed a critical spot. IntelliJ IDEA lets you fall back to a previous stack frame in a program's execution flow. This can be required in order to reproduce certain conditions or to test how the program deals with issues (for example, processes a null value or handles an exception).Īlso, this is convenient when you need to skip particular parts of the program that aren't related to the problem you are currently examining.

However, there are cases when you need to deviate from it.

While debugging an application, you typically follow the normal flow of a program.
