• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pls help me on Checked Exceptions

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
I could not understand the concept of checked exceptions? Can anyone explain me briefly what is it?where it can be used? how it is to be used?
Thanks in advance.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checked exceptions are those that the compiler checks.. if there is a probability that a block of code could throw a kind of checked exception it should be having a catch block with that exception.. otherwise the compiler will complain..
Hope this helps.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checked Exception are those which are subclass of Exception but not RuntimeException and subclass of RuntimeException.
Sunita is right that Checked Exceptions are checked by compiler for handling the exception either by try/catch block or throws clause. That is if a method may through a checked exception it may handle it inside the method using try/catch block or it can use a throws clause for its caller method to handle the exception.
Ambapali
 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sunita and Ambapali...short and sweet answer...now i have quick idea abt what it is.
Thanks
Karthik
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is exception is not a run time error
or it is cheaked by JVM
i hope it is right
kay if exception is create or a object i create
and object go to Exception class and find his sub classes
but you al of r talking abt compiler
is complier also cheak exception
plz help me in it. I m student
Faheem
 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checked exceptions are different from runtime exceptions or unchecked exceptions. If you dont catch runtime exceptions the compiler does not complain.. It is because it is not expected in the normal execution of the program...
Hope this helps.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch bhatti.
Runtime exceptions are supposed to represent programmers bugs. For instance accessing a non existing array element -ArrayIndexOutOfBoundException- , or calling a method with a non valid argument -IllegalArgumentException-
Because they are possible to ocurr at so many places in the code, it is not feasible that all the expressions possibly throwing them are to be placed within a try clause. Besides, given that they represent programmer errors, the programmer itself should round them in a try clause if they were checked ones. But, if the programmer knew that a runtine exception (programmer error) is going to result from an expression, why placing it within a try clause?, Just correct the expression to avoid it.
Checked exceptions, on the other hand, represent non programmers errors, for which is valid to try to recover. Tipically accessing IO could fail in a file. The programmer is obliged for the compiler to manage the possibility of failure; either in a inmediately enclosing try/catch clause, or by declaring the exception to be thrown, in a calling method of the method where the exception was thrown.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the other thought, the compiler does not force the programmer to manage the possibility of failure. Because it is possible simply to declare the exceptions in all the methods participating in the call stack. The compiler merely forces the programmer to be aware of what kind of exceptions could be thrown. However the recommendation is to catch the exceptions in a context in which enough information exists for recovering.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic