This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt related to exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt related to exceptions" Watch "Doubt related to exceptions" New topic
Author

Doubt related to exceptions

Rohit Raghunath
Greenhorn

Joined: Apr 01, 2012
Posts: 15
package SelfTest;





In the above code doStuff() is overridden and declares that it throws ArithmeticException.....whereas the method in base does not declare any exceptions!!!

how come then it is allowed to throw ArithmeticException....isn't ArithmeticException a checked exception??
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3419
    
  12
Click on that link that was auto added to your post and you'll get your answer.


Joanne
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Rohit Raghunath wrote:package SelfTest;

class MyException extends Exception { }

class Tire { void doStuff() { } }

public class ST_C5_16 extends Tire
{
public static void main(String[] args)
{
new ST_C5_16().doStuff();
}


void doStuff() throws ArithmeticException
{
System.out.println(7/0);
}
}




In the above code doStuff() is overridden and declares that it throws ArithmeticException.....whereas the method in base does not declare any exceptions!!!

how come then it is allowed to throw ArithmeticException....isn't ArithmeticException a checked exception??


Please use code tags.

Regarding your question first of all i would advice you to keep JLS and JAVADOC API in your arsenall. as you can see here http://docs.oracle.com/javase/6/docs/api/java/lang/ArithmeticException.html Arithmetic exception is not checked exception. it is unchecked exception .
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

what you are talking about will not apply to an unchecked exceptions(runtime exceptions)
raju salla
Greenhorn

Joined: Jan 05, 2012
Posts: 18
Hello Guyz,
Related to your doubt about the exceptions, the overriden method can throw any exception that is subclass of the exception which is thrown by the base class method and also it might throw any RuntimeException. As ArithmeticException is subclass of RuntimeException the overriden method can throw arithmetic exception.

Thanks and Regards
Raju Salla
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt related to exceptions
 
Similar Threads
"Handle or Declare" Rule for Checked Exceptions
K&B Book,chapter 5
Exceptions & overriding?
SCJP Question
Understanding Exception Hierarchy