Skip to content
Advertisement

How to apply user defined try catch block in java

I am a beginner and I’ve finished the basic Nim game. Now I want to apply the try catch block to the program to make sure the flow control is perfect. However, the resources I’ve seen for now is to catch the exception in the main method that all the methods created must be called in the try block to catch the exception.

In my case, I create my class’s constructor to call the processCommands panel. Then, this panel calls the other methods in the class.

I need to catch the user input commands in the panel to see whether the commands is valid.

I’ve tried: https://beginnersbook.com/2013/04/user-defined-exception-in-java/

But it seems that I have to reconstruct the methods I’ve built so far. Is there any way to fix this?

Any help is appreciated. Thank you for your kindness and patience.

Here is part of my Nimsys:

JavaScript

Advertisement

Answer

JavaScript

}

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement