• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compiler question help

 
Paddy Joshi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how compiler find in comilation time whether that exception is checked are unchecked ?
 
shivdhwaj pandey
Ranch Hand
Posts: 67
Java PHP Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
describe you question please
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiler sees whether an Exception extends RuntimeException if that then its unchecked Exception otherwise its checked one.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21431
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic