• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exiting a Java Program  RSS feed

 
harish shankar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking to terminate my current java program by not calling a exception or a System.exit ,are there any other ways in java to terminate my java program alone and not the JVM has such.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this an interview question? Otherwise I can't see any reason for not using the mechanisms designed for this purpose.

As a possible answer: you can use JNI to retrieve and close the current process.
 
harish shankar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No certainly its not a intv question... in the code there is no exception handling and it is a quite deep nested calll , i am trying to using reflection,which wil force me to either catch a excpetion or throw... if i throw i need to declare the throws in lot of places...so was thinking ,if I can catch the exception and the program...
 
harish shankar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
harish jss wrote:No certainly its not a intv question... in the code there is no exception handling and it is a quite deep nested calll , i am trying to using reflection,which wil force me to either catch a excpetion or throw... if i throw i need to declare the throws in lot of places...so was thinking ,if I can catch the exception and the program...


Also not sure how JNI will help here...
 
Stephan van Hulst
Saloon Keeper
Posts: 7928
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With JNI you can make a syscall to the OS to terminate the process.

But I think that's hardly justified for what you're trying to do. I don't really see what the problem is. Why do you want to exit the program?

If you want to exit the program because an error occurred, you can just throw an exception. If you want to exit because you want to exit, you can use System.exit().

Why is it not possible to use these mechanisms?
 
harish shankar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:With JNI you can make a syscall to the OS to terminate the process.

But I think that's hardly justified for what you're trying to do. I don't really see what the problem is. Why do you want to exit the program?

If you want to exit the program because an error occurred, you can just throw an exception. If you want to exit because you want to exit, you can use System.exit().

Why is it not possible to use these mechanisms?

Well as I told earlier this is a existing code deep inside.. if i add a throws exception than I need to add this throws exception in number of places...
 
Paul Clapham
Sheriff
Posts: 22701
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
harish jss wrote:Well as I told earlier this is a existing code deep inside.. if i add a throws exception than I need to add this throws exception in number of places...


Yes. So do that... except I was going to suggest you also had the option of catching the exception and handling it locally, but you seem to have decided that these exceptions (whatever they are) can't be handled locally. you should however evaluate each of the levels which are supposed to pass on the exceptions and decide whether they could handle those exceptions.
 
Stephan van Hulst
Saloon Keeper
Posts: 7928
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what is the nature of the error? You really aren't telling us much.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harish, please read your private messages.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!