• 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

Constructor declations

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,

I m havind one doubt regarding constructor declarations.

when i write
class A {A() throws ArithmeticException {}} // 1
class B extends A {B() throws Exception {}} // 2
class C extends A {C() {}} // 3


it doesnt give any compilation error

but when i write
class A {A() throws IOException {}} // 1
class B extends A {B() {}} // 2
class C extends A {C() {}} // 3



It gives compilation eror
"Unhandled exception type IOException"

so can anybody tell me the reason?
 
Gauri Horane
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-- sorry i want to write like this
*****************************************
Hello Everybody,

I m havind one doubt regarding constructor declarations.

when i write
class A {A() throws ArithmeticException {}} // 1
class B extends A {B() {}} // 2
class C extends A {C() {}} // 3


it doesnt give any compilation error

but when i write
class A {A() throws IOException {}} // 1
class B extends A {B() {}} // 2
class C extends A {C() {}} // 3



It gives compilation eror
"Unhandled exception type IOException" at 2, 3

so can anybody tell me the reason?
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the difference between ArithmeticException and IOException and you'll notice immediately why you need to catch one and not the other.
 
Gauri Horane
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Jeroen ,
i understood IOException is checked Exception , so it should be explicitle handled in the code.
Thanks for ur help
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gauri Horane:
thanks Jeroen ,
i understood IOException is checked Exception , so it should be explicitle handled in the code.
Thanks for ur help


Or you can declare it in the throws clause:


Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic