Carey Brown wrote:In Java the use of System.exit() is discouraged because open resources may not be closed properly. Exit() means "I don't care what you're in the middle of, stop and leave the program". Catch on the other hand says "ok, I got this and I'll do something meaningful with it and then continue", which is exactly the opposite. Why wouldn't you just throw and exception if you want to catch it?
Monica Shiralkar wrote:I mean the case where one program calls another program and the second program give exit(1) and we have to catch it.
Monica Shiralkar wrote:I mean the case where one program calls another program and the second program give exit(1) and we have to catch it.
Campbell Ritchie wrote:Will a shutdown hook run when System.exit() is called?
Monica Shiralkar wrote:When anyway Java has a shut down hook mechanism through which one can do this then what is the reason that it was not made so that Catch block could catch System.exit(1) ?
Paul Clapham wrote:
Campbell Ritchie wrote:Will a shutdown hook run when System.exit() is called?
Yes.
Paul Clapham wrote:
And remember what the purpose of System.exit is. The purpose is to end the program. So making it possible for something else in the code to intercept that, so that the program does not actually end, would be an incoherent design.
Carey Brown wrote:You haven't been crystal clear on this but I'm sensing that if the CALLED program does an exit(1) that you expect that the CALLING program will throw an exception. Yes? No?
...
and the CALLING program is supposed to exit(1) also?
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
waitFor() returns the same value.Paul Clapham wrote:I notice that the Process class has an exitValue() method; it returns an int value which I suspect would be the "1" in Monica's example.
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|