• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exception's

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class drum
{
void method2(int j)
{

}
}
class vote extends drum
{
void method2(final int j)throws ArithmeticException
{

}
}
hello everybody,
in the above code i have taken two classes in which i am basically doing overriding.
My question is when i override the method2() in the vote class i specify an ArithmeticException in it's clause and it does not give an error.
If i put any other exception out there like interruptedException,or nullpointerexception i get an error throw's clause not compatible.
I think the rules for overrriding are
1)The exception thrown in overridden method can be specified in the throws clause of the overriding method.
2)or the subclass of the exception or do not specify any exception in the overriding method.
please throw some light on it.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi nitin,
there are two kind of exceptions-----
1) Caught Exceptions
2) Uncaught Exceptions
the caught exceptions are those exceptions which can be caught at the compile time i.e., you can specify them in throws clause or in try-catch block.
the uncaught exceptions are those exceptions which your jvm is unable to handle at the runtime and are thrown by the jvm at the runtime,

ArithmaticException is a caught exception i.e., you can trap it and process accordingly, but if something goes null how will you assign or specify something at runtime when your compiler hasn't generated the bytecode for that.
similar case is with InterruptedException (when a thread interrupted) can't be thrown instead it can be caught and processed accordingly.

lets say a thread is interrupted somehow, now if you want to throw this exception , which thread will execute the code for throwing this exception i.e.(..throws InterruptedException)
so you have to catch this exception in any case.
 
Hug your destiny! And hug this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic