• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Returning error code from jar application

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure, you came across the similar situation or there is a solution for this problem.

I need to return an error code from my jar application to the calling application. This jar application does some core java functionality and if it finds any unusal situation while executing the code, then it returns with the error code to the calling function. The calling function may be a unix shell script.

Can I use System.exit(n) to return the error code? Can this return value be received by the calling function? Please let me know your answers

Thanks,
Makesh
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally System.exit(0) kills the JVM, so it may not return you any values.

Thanks
Chandu
 
Makesh Kumar Ramakrishnan
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is, System.exit(0) is a normal exit of JVM. and System.exit(1) is forced shutdown of JVM.
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.
API
[ February 27, 2006: Message edited by: Chetan Parekh ]
 
Makesh Kumar Ramakrishnan
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can this returned status code be properly received by the calling application?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Makesh Kumar Ramakrishnan:
Can this returned status code be properly received by the calling application?



Yes, it can. That is in fact the only purpose of the parameter - to serve as an error code returned to the caller.

It probably would have been faster and easier to simply try this, wouldn't it?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Makesh Kumar Ramakrishnan:
My understanding is, System.exit(0) is a normal exit of JVM. and System.exit(1) is forced shutdown of JVM.



No, the JVM exits in the same way, regardless of the error code. The code simply is passed to the operating system, which passes it to the caller (if the OS supports it).
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ilja Preuss, what System.exit(-1) do?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chetan Parekh:
Hey Ilja Preuss, what System.exit(-1) do?



The same as System.exit(42) or System.exit with any other value, just with a different exit code, of course.

Why do you ask? Did you expect it to do something special?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:


The same as System.exit(42) or System.exit with any other value, just with a different exit code, of course.

Why do you ask? Did you expect it to do something special?



Hey Ilja , you are right. I had a conception that when you use System.exit(-1), than only JVM will killed. I checked here and regardless of the values I pass, System.exit() kills the JVM.

Thnaks
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic