This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Test {


public void testRE() {

try {

throw new RuntimeException();
} catch(Exception e) {
System.out.println("caught exception");

}
}



}

RuntimeException is Throwable...then why compile error!!!

i get confused with try catch finally blocks when they are in a method and try to return something...is there any good reference that might help??
regards
Sajid
 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more question....
in some cases the compiler eats up exception...( like in a finalize method ) is there any other such case??

sajid
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing that the compiler could complain about. However, there would be a problem if Exception were thrown but RuntimeException is handled.
 
Marcelo Ortega
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what version compiler you using?
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Test16 {


public void testRE() {
try {
throw new RuntimeException();
}
catch(Exception e) {
System.out.println("caught exception");
}
}
public static void main(String args[])
{
Test16 t= new Test16();
t.testRE();
}
}


i compiled this with java 1.4.2

no problem in compilation and program run fine
 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry all..it was my fault...I had another class named RuntimeException (which didn't extend throwable ) in my class path and I didn't know that....sorry again
sajid
 
Timmy Marks
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very good reason to avoid the default package whenever possible!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic