Help coderanch get a
new server
by contributing to the fundraiser
  • 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

CHecked Exception

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In very simple terms, checked exception are a subset of the exceptions that are checked by the compiler and flagged(code will not compile) if they are not handled by the method
1. either in a try catch block or
2. not propogated by that method by declaring the method as throws SomeChecked excpetion.
Of the Exception class, there is the RunTimeException subclass and its sub classes and there are other subclasses.The RuntimeException and its subclasses are not checked exceptions.

The other exceptions include IOException and its subclasses for e.g.
A simpler way to remember is that all Exception other than
1. Exception class.
2. RuntimeException and its subclasses
are checked exception.
Trust this helps.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Except for RuntimeException, Error and their subclass, all exceptions are called checked exceptions.
the compiler ensures that if a a method can throw a checked exception , derectly or indirectly, the the method must explicitly deal with it.
the method must either cathch the cxeption and take the appropriate acton, or pass on the exception to its caller.
------------------
Jeff
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello
I wanted to know, if we are calling a finalize() method ,why we have to catch the Throwable exception or we have to mention that it throws this exception
i.e
public static void main(String s[]) throws Throwable
{
new Object().finalize();
}
why we have to include a throws clause or we have to catch this exception.
Is Throwable/Exception is consider as a Checked Exceptions ?

public void fun()
{
// code not throwing any IOExceptions
}
catch(IOException e)
{}
this code will cause an compile time error. as IOException is checked exception.
public void fun()
{
//code not throwing any kind of exception
}
catch(Exception e)
{}
This is compile and run perfectly
Is there is some rule which i am missing

 
I was born with webbed fish toes. This tiny ad is my only friend:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic