When I run my java project, either using "gradle run" or running the Main method from Intellij, if I get an error, the program simply stops executing with "Process finished with exit code 0". For example, if I try to access an array at the wrong index, the program stops and no errors are shown. I tried wrapping in a try statement the code in my main method, but nothing changes.
1 Answer
In my brief experience with this IDE, indeed out of the box it will not print any details about any exception, even uncaught at top level. So, by default, you get less info from this IDE than running your app in terminal.
OTOH that can be remedied by dialog-box-diving about 3 layers deep. I don't remember the initial settings for [all] those dialogs (I should have taken a screenshot, LOL) but the gist of it is that you have to think as if you were coding a JDI app!
- Go to breakpoints: set it to report/break on uncaught exceptions. (By default it won't). This config can be found in the lower left corner under that bug icon under the tiny icon with two overlapping red circles! The top toolbar (which has a similar bug icon) doesn't have this breakpoints stuff. (Perhaps it can be configured to have it, IDK.) As you hover over the two little red circles, it will hint you the shortcut for that is Ctrl+Shift+F8.
- Also, you might want to filter to the classes of interest, just in case. This might not be needed just for the uncaught exceptions, but the caught ones are checked by default, and will break in all sorts of places, deep in the libraries.
- Run again. Then it will do what other IDEs do out of the box, i.e. show you where your pogram 'died'.
Now to be more fair to IDEA's debugger as I bashed a bit here for it being newbie unfriendly, once you get past that initial 'huh' of it doing nothing by default, it is fairly useful as you can see e.g. inline in the code view (above) what is null in that exception. Which would definitely take more work e.g. with jdb. (Aside, I think IDEA also recompiles all dependencies with -g to get local variable info... everywhere. A gradlew compile of that project took under 1s on the command line [probably because it just the precompiled binaries for the dependencies], but in IDEA [then] that took 16s because I think it did a full recompile of dependencies with -g.)




> Process 'command '/usr/lib/jvm/java-1.8.0-amazon-corretto/bin/java'' finished with non-zero exit value 1. It suggests to run with--stacktracewhich if you click does nothing different! It doesn't even print the exception that you can see if you run the app in terminal. IDEA is bar far the worst IDE experience ever, for me.