aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compiler question help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compiler question help" Watch "compiler question help" New topic
Author

compiler question help

Paddy Joshi
Greenhorn

Joined: Oct 13, 2010
Posts: 10
how compiler find in comilation time whether that exception is checked are unchecked ?
shivdhwaj pandey
Ranch Hand

Joined: Nov 12, 2011
Posts: 67

describe you question please


with regards,
Shivdhway Pandey
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281

Compiler sees whether an Exception extends RuntimeException if that then its unchecked Exception otherwise its checked one.


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
11.2 Compile-Time Checking of Exceptions might help -

A compiler for the Java programming language checks, at compile time, that a 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 possible result, the throws clause for the method (§8.4.6) or constructor (§8.8.5) 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.



Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Javin Paul wrote:Compiler sees whether an Exception extends RuntimeException if that then its unchecked Exception otherwise its checked one.


This cant be right. RuntimeException is a subclass of Exception. All checked exceptions are also subclasses of Exception so i doubt that it does it by just checking wether the exception is an instance or RuntimException.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

O. Ziggy wrote:
Javin Paul wrote:Compiler sees whether an Exception extends RuntimeException if that then its unchecked Exception otherwise its checked one.


This cant be right. RuntimeException is a subclass of Exception. All checked exceptions are also subclasses of Exception so i doubt that it does it by just checking wether the exception is an instance or RuntimException.


Why not? All checked exceptions may be subclasses of Exception, but they are not subclasses of RuntimeException. It is possible to subclass from the Exception class without subclassing from the RuntimeException class. So, you can tell if an exception is unchecked by checking the instance to see if it is an instance of a RuntimeException.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Henry Wong wrote:
O. Ziggy wrote:
Javin Paul wrote:Compiler sees whether an Exception extends RuntimeException if that then its unchecked Exception otherwise its checked one.


This cant be right. RuntimeException is a subclass of Exception. All checked exceptions are also subclasses of Exception so i doubt that it does it by just checking wether the exception is an instance or RuntimException.


Why not? All checked exceptions may be subclasses of Exception, but they are not subclasses of RuntimeException. It is possible to subclass from the Exception class without subclassing from the RuntimeException class. So, you can tell if an exception is unchecked by checking the instance to see if it is an instance of a RuntimeException.

Henry



I stand corrected..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compiler question help