Questions tagged [system.exit]
73 questions
307
votes
12 answers
Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java
I'd like to know the difference between the following in Java
System.exit(0);
System.exit(-1);
System.exit(1);
When do I have to use the above code appropriately?

giri
- 26,773
- 63
- 143
- 176
90
votes
6 answers
How does Java's System.exit() work with try/catch/finally blocks?
I'm aware of headaches that involve returning in try/catch/finally blocks - cases where the return in the finally is always the return for the method, even if a return in a try or catch block should be the one executed.
However, does the same apply…

Thomas Owens
- 114,398
- 98
- 311
- 431
38
votes
5 answers
Running code on program exit in Java
Is it possible to write a method that System.exit will call when you terminate a program?

Alex
- 5,364
- 9
- 54
- 69
13
votes
2 answers
Does Android care about exit status code passed to System.exit(...)?
If I kill an Android app with System.exit(...), does it matter what status code I pass? I couldn't find any documentation on whether Android just ignores it or whether certain ones lead to any error messages for example or have any other meaning.

Markus A.
- 12,349
- 8
- 52
- 116
9
votes
3 answers
System.exit() in android
I know system.exit(0) should not be used.
I have read plenty of tutorials as well stating why it's not recommended for exiting applications and finish() is a better alternative ,but in very rare case when this dirty workaround is used than my main…

Altavista
- 253
- 5
- 12
7
votes
5 answers
System.exit() results unexecutable finally block
I am working on My application's under maintanace module
try {
if (isUndermaintanace) {
System.exit(1);
} else {
prepareResources();
}
} catch (Exception e) {
printStack(e);
} finally {
…

Suresh Atta
- 120,458
- 37
- 198
- 307
6
votes
4 answers
difference between System.exit(0) and System.exit(-1)
Can any one share to me difference between System.exit(0) and System.exit(-1) it is helpful if you explain with example.

ramana
- 79
- 2
- 4
- 5
6
votes
2 answers
Android: Show toast after finishing application / activity
I want to show a simple toast, when exiting an application. The problem is, that the toast is not shown. I assume it is because the acitivity is finished or because of System.exit(0), but I don't know how to solve it. Does anyone have a tip?…

Sebastian Büttner
- 61
- 1
- 3
5
votes
4 answers
How can I exit only my sub-program, not the whole VM?
I have a Java swing launcher program to launch another class (running its main method).
Each program has its cancel button to exit itself.
I use System.exit(0); when this cancel button is pressed.
The launcher program does this in…

hkguile
- 4,235
- 17
- 68
- 139
5
votes
2 answers
How to prevent shutdown hook from getting deadlock?
I've seen a question here asked by @Tej Kiran which is exactly my question but it is not answered, the last comment says:
"Do you know if there are any shutdown hooks registered in your
application, or if any of the libraries you are using that…
user3777963
4
votes
2 answers
Force quit of Android App using System.exit(0) doesn't work
when I try to quit my Android application by overwriting the function for the back-button of Android devices and "System.exit(0)", this doesn't work.
I have an activity named "LoginActivity" and an activity named "OverviewActivity".
When I start an…

Maarkoize
- 2,601
- 2
- 16
- 34
3
votes
3 answers
Exit Android application from application class (Not activity)
Is there a way to exit android application from the Application class itself.
This is even before any activity has been initialized.
Scenario is user side-loading the build in an unsupported device which leads to crashes when I try to load…

Raghav
- 1,014
- 2
- 16
- 34
3
votes
2 answers
Movie ended on JMF,now terminate program
I want my program to terminate itself once the movie played has ended,
using system.exit(0).
is there a way of doing that?
I dont want to use Timer.

Itzik984
- 15,968
- 28
- 69
- 107
3
votes
2 answers
Java: Reset button isn't working
Ok so i am creating this program that when you click on the reset button, it closes the program and opens a new same program from starting however, I am not able to understand how to do it :/ Here is my code for button .. This code basically exits…

the feels
- 107
- 1
- 7
3
votes
4 answers
Why does the addActionListener method need these stages?
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ea){
System.exit(0);
}
});
I am learning Java and saw the above code.
I can't understand why the addActionlisetner method needs…

Ye-Young Jeon
- 33
- 3