What is an appropriate way to programmatically exit an application?

后端 未结 6 1614
慢半拍i
慢半拍i 2021-01-26 17:57

I am evaluating user inputs as commands for my application. If the user presses Q, or q, and then hits enter, the application quits and execution terminate

6条回答
  •  萌比男神i
    2021-01-26 18:13

    Returning all the way back to Returning out of main() is the cleanest way, of course, but if that's not easy to do, System.exit() is perfectly fine.

    It's not directly relevant to your question, but throwing an (unhandled) exception is usually the way to terminate on a fatal condition, since it provides a lot of tracing info to the poor user.

提交回复
热议问题