Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: why should we declare checked exceptions?

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default why should we declare checked exceptions?

    Hi !My doubt is on checked,unchecked exceptions in java.
    1)You know that if there is any possibility for checked exception to be thrown from a method and we do not have intention to handle the thrown exception then we have to declare that exception in method header.That means we have to write “throws EXCEPTION NAME” in method header.
    2)But in case of unchecked exception, if there is any possibility for unchecked exception to be thrown from a method then we do not declare that exception in method header.. That means we do not write “throws EXCEPTION NAME” in method header .
    3)Why should we declare the exception in method header in case of checked exceptions ? what benefits are we getting by declaring exception in method header?
    4)Why do not we declare the exception in method header in case of unchecked exceptions?


  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: why should we declare checked exceptions?

    in case of checked exceptions-it follows throw early catch later principal which is necessary for handling the exceptions.
    in case of unchecked exceptions-we donot know the type of exception, they occur at runtime. so we cannot throw the unchecked exceptions.

Similar Threads

  1. Suggestion to declare variable that is declared
    By zlloyd1 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 28th, 2013, 05:32 PM
  2. How to declare byte enum
    By alex007 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 6th, 2012, 04:51 AM
  3. See if checkbox is checked
    By kney in forum Java Theory & Questions
    Replies: 9
    Last Post: December 7th, 2011, 06:23 AM
  4. caught or declare might be thrown error
    By IDK12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 28th, 2011, 12:55 PM
  5. [SOLVED] How to declare an object of multi-dimension array?
    By FongChengWeng in forum Collections and Generics
    Replies: 7
    Last Post: January 14th, 2011, 12:17 AM