Results 1 to 3 of 3
Thread: why we need checked exceptions
- 12-03-2011, 05:54 PM #1
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
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.
Ex:
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. :-)
- 12-03-2011, 07:11 PM #2
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
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.
- 12-03-2011, 07:51 PM #3
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
-
Exceptions?
By linc186 in forum New To JavaReplies: 3Last Post: 03-07-2011, 08:03 AM -
What method to use to get VALUE of the only checked radio in the current page
By lse123 in forum Advanced JavaReplies: 1Last Post: 12-16-2010, 02:39 PM -
please explain multiple inheritence by an example lot of tutorial i checked but not
By javastuden in forum New To JavaReplies: 1Last Post: 02-08-2010, 01:57 PM -
radio button checked by default
By whiteasshweta in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 07-06-2009, 01:11 PM -
Checked Exception
By Java Tip in forum Java TipReplies: 0Last Post: 11-18-2007, 06:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks