EXCEPTIONS
Why Runtime Exceptions are Not Checked
11.2.2
11.2   Compile Time Checking of Exceptions
The Java language checks, at compile time, that a Java program contains handlers
for
checked exceptions
, by analyzing which checked exceptions can result from
execution of a method or constructor. For each checked exception which is a pos 
sible result, the
throws
 clause for the method ( 8.4.4) or constructor ( 8.6.4)
must mention the class of that exception or one of the superclasses of the class of
that exception. This compile time checking for the presence of exception handlers
is designed to reduce the number of exceptions which are not properly handled.
The
unchecked exceptions classes
 are the class
RuntimeException
 and its
subclasses, and the class
Error
 and its subclasses. All other exception classes are
checked exception classes
. The standard Java API defines a number of exception
classes, both checked and unchecked. Additional exception classes, both checked
and unchecked, may be declared by Java programmers. See  11.5 for a descrip 
tion of the Java exception class hierarchy and the exception classes defined by the
standard Java API and Java Virtual Machine.
The checked exception classes named in the
throws
 clause are part of the
contract between the implementor and user of the method or constructor. The
throws
 clause of an overriding method may not specify that this method will
result in throwing any checked exception which the overridden method is not per 
mitted, by its
throws
 clause, to throw. When interfaces are involved, more than
one method declaration may be overridden by a single overriding declaration. In
this case, the overriding declaration must have a
throws
 clause that is compatible
with
all
 the overridden declarations ( 9.4).
Variable initializers for fields ( 8.3.2) and static initializers ( 8.5) must not
result in a checked exception; if one does, a compile time error occurs.
11.2.1   Why Errors are Not Checked
Those unchecked exception classes which are the
error classes
  (
Error
 and its
subclasses) are exempted from compile time checking because they can occur at
many points in the program and recovery from them is difficult or impossible. A
Java program declaring such exceptions would be cluttered, pointlessly.
11.2.2   Why Runtime Exceptions are Not Checked
The
runtime exception classes
  (
RuntimeException
 and its subclasses) are
exempted from compile time checking because, in the judgment of the designers
of Java, having to declare such exceptions would not aid significantly in establish 
ing the correctness of Java programs. Many of the operations and constructs of the
203






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved