Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Doubt related to exceptions

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Click on that link that was auto added to your post and you'll get your answer.
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 .
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you are talking about will not apply to an unchecked exceptions(runtime exceptions)
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic