There is a program in which some data is entered. How to make the program close when entering incorrect data?

  • five
    And what prevents everywhere to do return - and the program will end. - nick_n_a
  • What prevents to check whether the process is alive by an open descriptor from "within this program" and also terminates. - nick_n_a

2 answers 2

To complete the process, use Environment.Exit .

    You need to throw an exception, like:

    throw new Exception("Пипец всему!"); 

    Or just

     void Main(){ //твой код if (error) return; } 
    • What is the minus? Answer on the topic, everything works. - Balsoft
    • What is the exception? It does not close the program at all. - Pavel Mayorov
    • Oh damn, I completely forgot - Balsoft
    • It just stops the execution of the program, isn't that necessary? - Balsoft
    • 6
      The thrown exception is accepted to be caught and processed. And during processing, the same problem arises - how to shut down the program. That's why I say - the exception has nothing to do with it, the program is closed with no exception. - Pavel Mayorov