For a CS project, I need to have my program "gracefully terminate" in case of certain user input errors. What is the best syntax to do this?

Recommended Answers

All 3 Replies

idk how graceful try-catch blocks are but those should do the trick when coupled with System.exit(0)...

System.exit is what we are not allowed to use.

You'll have to structure your program then so that it's flow of control naturally terminates it.

boolean validInput = true;
          
while( validInput )
{
    // do all the stuff my program is meant to do

   if user enters invalidInput then
      display a message
      validInput = false

}

that sort of thing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.