3

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.

4
  • 1
    which framework are you using? The docs.oracle.com/javase/7/docs/api/java/lang/… handles what happens when an exception is caught, and whether or not this is translated to an exit code depends on how you run your program. Commented Dec 14, 2016 at 13:41
  • I am not sure, all I did to setup the project was run "gradle init" Commented Dec 14, 2016 at 15:35
  • Paste your try-catch code please. Commented Dec 15, 2016 at 10:05
  • @AlexanderTorstling: it doesn't matter, the behavior is the same out-of-the box, no matter the project, AFAICT. > 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 --stacktrace which 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. Commented Jul 5, 2024 at 18:26

1 Answer 1

0

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.

enter image description here

enter image description here

  • 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.

enter image description here

  • Run again. Then it will do what other IDEs do out of the box, i.e. show you where your pogram 'died'.

enter image description here

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.)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.