File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Sajid Moinuddin
Ranch Hand

Joined: Mar 19, 2005
Posts: 85
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

Joined: Mar 19, 2005
Posts: 85
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

Joined: Sep 29, 2002
Posts: 1683
There is nothing that the compiler could complain about. However, there would be a problem if Exception were thrown but RuntimeException is handled.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 525

what version compiler you using?


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
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


Thanks and Regards, Amit Taneja
Sajid Moinuddin
Ranch Hand

Joined: Mar 19, 2005
Posts: 85
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

Joined: Dec 01, 2003
Posts: 226
A very good reason to avoid the default package whenever possible!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception Handling