nus-cs2103-AY2425S1 / forum

12 stars 0 forks source link

Exception Handling works on VSCode but not on IntelliJ #342

Closed yu-sutong closed 1 month ago

yu-sutong commented 1 month ago

I believe I handled my exception correctly, and when I run my code on VSCode, typing an invalid command will not crash my program. However on IntelliJ, it crashes the program. May I know how to resolve this issue on IntelliJ? Thank you very much!

Screenshot 2024-09-19 at 12 58 07 AM Screenshot 2024-09-19 at 1 00 26 AM
damithc commented 1 month ago

@yu-sutong Is this version of the code in your fork's master branch (so that others can try to replicate problem)?

yu-sutong commented 1 month ago

Yes Prof.

TohLiYuan commented 1 month ago

Hi, I'm a senior from a previous batch

This is the intended behaviour of the IntelliJ debugger, once it encounters any new Exceptions, it will automatically switch to the Exception view to help you debug it, regardless of whether or not the Exception has been handled. Your program did not crash and you should be able to continue using it in the main Terminal window, circled in this edited screenshot

image
neyapraveen commented 1 month ago

Hi, I'm a senior from a previous batch, just dropping by the forum to see if I can help. As @TohLiYuan mentioned, this is due to the nature of IntelliJ, and you have 3 main workarounds to this problem:

  1. Continue Running the Program: After IntelliJ shows the exception in the debugger, you can switch back to the main terminal or console window to observe that the program is still running as expected.
  2. Disable Break on Exception: If you prefer IntelliJ not to pause when an exception is thrown (even handled ones), you can configure this in your settings. Go to Run > View Breakpoints, and in the Breakpoints window, uncheck "Caught Exceptions" under the Exception Breakpoints. This will stop IntelliJ from breaking at handled exceptions.
  3. Check Exception Filters: You can also filter which types of exceptions the debugger will break on, which allows more control over when IntelliJ halts execution.

Hope this helps!

damithc commented 1 month ago

@yu-sutong If the above replies don't help you solve the problem, you may wish to post a screen recording of your Intellij session, so that we can see exactly how you ended up in the view shown in the screenshot.

yu-sutong commented 1 month ago

@TohLiYuan @neyapraveen Thank you for the help and it has solved my issues!

I tried option 2 too, which is unchecking "Caught Exceptions", but that didn't stop IntelliJ from breaking at handled exceptions. I will move on with option 1 and always switch back to the main terminal.

Screenshot 2024-09-19 at 8 02 48 PM
nus-se-bot commented 1 month ago

@yu-sutong A gentle reminder to close this issue if the problem has been resolved. If not resolved yet, please post a comment explaining which part of the problem/question remains unresolved.

nus-se-bot commented 1 month ago

@yu-sutong I'm closing this issue due to inactivity. Feel free to reopen if the issue is still unresolved.