Saturday, June 27, 2015

Uncaught Exception in Java: Yet Program Exits with Success?

In Java, you would have noticed that if we get an uncaught exception JVM exits with success (exit code is zero). While in C++ if there is an exception which is not handled, program returns with non-zero Exit Code. Only in case of explicit System.exit(), do we a non-zero Exit code, which reflects Failure. 

Some consider this a design issue, some consider this s defect. When such a code is called from within a script, coders tend to rely on exit status. They get confused often in Java as Success does not mean every time a successful exit.

What should we do in Java?
Write a top level try-catch in main. If any Exception is there, catch it and throw System.exit(1) explicitly. In an already written code that you are using, don't rely on exit codes.

6 comments:

  1. Nice blog. Really helpful information about Java …. Please keep update some more…………

    ReplyDelete
  2. And indeed, Iam just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I have had.Blue Prism Training in Chennai
    Angularjs Training in Chennai
    MCSE Training in Chennai
    AI Training in Chennai
    SEO Training in Chennai

    ReplyDelete
  3. Thanks for spending your valuable time to Create such a Thoughtful Post...It's Really useful for Now and my feature reference...Keep Updating Ever
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  4. I am regular reader of your blog from long time,What a Beautiful post! This is so chock full of useful information I can’t wait to dig and start using my time on blogging and I am looking for and I love to post a comment that "The content of your post is awesome" Great work!
    Java Training in Chennai

    Java Training in Velachery

    Java Training in Tambaram

    Java Training in Porur

    Java Training in OMR

    Java Training in Annanagar



    ReplyDelete