Questions tagged [exit]

Exiting, quitting, or halting refers to the termination of a process or program.

2585 questions
226
votes
8 answers

return statement vs exit() in main()

Should I use exit() or just return statements in main()? Personally I favor the return statements because I feel it's like reading any other function and the flow control when I'm reading the code is smooth (in my opinion). And even if I want to…
Srikanth
  • 11,780
  • 23
  • 72
  • 92
217
votes
35 answers

How to stop C++ console application from exiting immediately?

Lately, I've been trying to learn C++ from this website. Unfortunately whenever I try to run one of the code samples, I see that program open for about a half second and then immediately close. Is there a way to stop the program from closing…
Adam P
  • 4,603
  • 6
  • 31
  • 40
214
votes
3 answers

How to create an exit message

Is there a one line function call that quits the program and displays a message? I know in Perl it's as simple as: die("Message goes here") I'm tired of typing this: puts "Message goes here" exit
Chris Bunch
  • 87,773
  • 37
  • 126
  • 127
199
votes
22 answers

How to exit from the application and show the home screen?

I have an application where on the home page I have buttons for navigation through the application. On that page I have a button "EXIT" which when clicked should take the user to the home screen on the phone where the application icon is. How can I…
poojan9118
  • 2,373
  • 2
  • 17
  • 13
198
votes
10 answers

When should we call System.exit in Java

In Java, What is the difference with or without System.exit(0) in following code? public class TestExit { public static void main(String[] args) { System.out.println("hello world"); System.exit(0); // is it…
pierrotlefou
  • 39,805
  • 37
  • 135
  • 175
197
votes
8 answers

How do I abort the execution of a Python script?

I have a simple Python script that I want to stop executing if a condition is met. For example: done = True if done: # quit/stop/exit else: # do other stuff Essentially, I am looking for something that behaves equivalently to the 'return'…
Ray
  • 187,153
  • 97
  • 222
  • 204
191
votes
7 answers

What happens to a detached thread when main() exits?

Assume I'm starting a std::thread and then detach() it, so the thread continues executing even though the std::thread that once represented it, goes out of scope. Assume further that the program does not have a reliable protocol for joining the…
Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
185
votes
4 answers

How to exit a function in bash

How would you exit out of a function if a condition is true without killing the whole script, just return back to before you called the function. Example # Start script Do scripty stuff here Ok now lets call FUNCT FUNCT Here is A to come back…
Atomiklan
  • 5,164
  • 11
  • 40
  • 62
184
votes
4 answers

Exit a Script On Error

I'm building a Shell Script that has a if function like this one: if jarsigner -verbose -keystore $keyst -keystore $pass $jar_file $kalias then echo $jar_file signed sucessfully else echo ERROR: Failed to sign $jar_file. Please recheck the…
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
173
votes
6 answers

Doing something before program exit

How can you have a function or something that will be executed before your program quits? I have a script that will be constantly running in the background, and I need it to save some data to a file before it exits. Is there a standard way of doing…
RacecaR
  • 1,907
  • 2
  • 13
  • 7
159
votes
5 answers

How to know the reason why a docker container exits?

I have a Docker container running in a host of 1G RAM (there are also other containers running in the same host). The application in this Docker container will decode some images, which may consume memory a lot. From time to time, this container…
Li Bin
  • 1,701
  • 3
  • 12
  • 12
150
votes
6 answers

Correct way to quit a Qt program?

How should I quit a Qt Program, e.g when loading a data file, and discovered file corruption, and user need to quit this app or re-initiate data file? Should I: call exit(EXIT_FAILURE) call QApplication::quit() call QCoreApplication::quit() And…
daisy
  • 22,498
  • 29
  • 129
  • 265
150
votes
5 answers

What is the difference between exit() and abort()?

In C and C++, what is the difference between exit() and abort()? I am trying to end my program after an error (not an exception).
Nathan Stoddard
146
votes
3 answers

When to use os.Exit() and panic()?

Could someone explain the key differences between os.Exit() and panic() and how they are used in practice in Go?
Timur Fayzrakhmanov
  • 17,967
  • 20
  • 64
  • 95
131
votes
2 answers

How to abort an interactive rebase if --abort doesn't work?

I've got myself into a muddle via an interactive rebase, and I now wish to abort it. (i.e. go back to the point before I was dropped into interactive rebase mode, in my case via git pull --rebase.) The way to do this seems to be via git rebase…
mjs
  • 63,493
  • 27
  • 91
  • 122