• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Exiting a Java Program

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22700
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Saloon Keeper
Posts: 14490
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 14490
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, what is the nature of the error? You really aren't telling us much.
 
Rob Spoor
Sheriff
Posts: 22700
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harish, please read your private messages.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic