Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

What is the Problem With The Code

 
Ranch Hand
Posts: 207
3
Oracle MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone I am new at this Forum and I wanted to ask a question in this topic-> Exception Handling with Method Overriding in Java

There is a rule that-> If the superclass method declares an exception, subclass overridden method can declare same, subclass exception or no exception but cannot declare parent exception.

then why not this code is giving me Compile Time Error->

import java.io.*;  

class Parent{  

 void msg()throws ArrayIndexOutOfBoundsException{System.out.println("parent");}  

}  
 
class TestExceptionChild2 extends Parent{  

 void msg()throws IndexOutOfBoundsException{System.out.println("child");}  
 
 public static void main(String args[]){  

  Parent p=new TestExceptionChild2();  

  try{  

  p.msg();  

  }catch(Exception e){}  

 }  

}  



See I have made Parent Class method msg() to thorw ArrayIndexOutOfBounds Exception which is subclass of IndexOutOfBoundsException and in Derived Class method msg() I have thrown

IndexOutOFBoundsException which is parent of ArrayIndexOutOfBounds . Then why not the code giving me Compile Time Error. Please Help...

Thanks In Advance...
 
Enthuware Software Support
Posts: 4448
41
 
O Shea
Ranch Hand
Posts: 207
3
Oracle MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your quick reply. Thank you
 
O Shea
Ranch Hand
Posts: 207
3
Oracle MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One More Question-:>

Will Errors participate in Exception Propagation.
Since when I getting StackOverflowError in my program it dosen't giving me its Stack trace. It only showing that where error occur and not that who calls that exception method.
 
Paul Anilprem
Enthuware Software Support
Posts: 4448
41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

R Sr wrote:One More Question-:>

Will Errors participate in Exception Propagation.
Since when I getting StackOverflowError in my program it dosen't giving me its Stack trace. It only showing that where error occur and not that who calls that exception method.


There is no difference between errors and exceptions with respect to propagation. Please post your code and the output that you have trouble understanding.
 
O Shea
Ranch Hand
Posts: 207
3
Oracle MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 

Here output coming->   CAUGHT AN ERROR
                               
                                 java.lang.StackOverflowError
                        at Error.go(java:27)

   Now it is giving only Line 27 and not that method which calls it i.e, main method(It is not propagating from line 27 to main method who calls that code where exception occurs) . Why?



 
 
 
    Bookmark Topic Watch Topic
  • New Topic