Results 1 to 3 of 3
  1. #1
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Rep Power

    Red face why we need checked exceptions

    I have a doubt:

    Thing is we have checked exceptions if we wont handle those the compiler shows some errors in compilation not in runtime.
    So why cant we remove from java when we know they will come.

    to get a input from we must use throws IOException. we know it raise a exception why java people wouldn't removed it.

    Please excuse if any mistakes. please do the needful. :-)

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Rep Power

    Default Re: why we need checked exceptions

    Because exceptions let things fail cleanly instead of producing unexpected behaviour.

    Take ArrayIndexOutOfBoundsException for example. If you declare an array with 8 elements, it's your responsibility not to attempt to do anything with element 10, and if you try to do so then Java will complain. Correct me if I'm wrong, but I think in C and C++ there's no such check, and it'll happily look beyond the bounds of the array, where the memory could be populated with any data at all. This may or may not crash your program, but it'll make it much less easy to see what you're doing wrong.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power

    Default Re: why we need checked exceptions

    Checked exceptions often indicate errors that are external to the JVM, such as errors caused by bad user input, corrupt files, network problems, etc. We don't know they will come. We know they might come. Checked exceptions force the programmer to deal with the possibility of an error instead of just letting the program crash... or worse, continue running in an invalid state.
    Last edited by kjkrum; 12-03-2011 at 07:53 PM.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Exceptions?
    By linc186 in forum New To Java
    Replies: 3
    Last Post: 03-07-2011, 08:03 AM
  2. Replies: 1
    Last Post: 12-16-2010, 02:39 PM
  3. Replies: 1
    Last Post: 02-08-2010, 01:57 PM
  4. radio button checked by default
    By whiteasshweta in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 07-06-2009, 01:11 PM
  5. Checked Exception
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-18-2007, 06:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts