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 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

sudha siva
Ranch Hand

Joined: Sep 18, 2001
Posts: 30
class Test2
{
public static void main(String[] args)
{
int d = 0;
try
{
int i = 1 / (d* doIt());
} catch (Exception e)
{
System.out.println(e);
}
}
public static int doIt() throws Exception
{
throw new Exception("Forget It");
}
}
The output of the above code is java.lang.Exception Forget it.I don't how the Forget it in doIt() printed out.Can anyone explain me.

Thanks
sudha
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
Originally posted by sudha siva:
class Test2
{
public static void main(String[] args)
{
int d = 0;
try
{
//1 int i = 1 / (d* doIt());
//4 } catch (Exception e)
{
//5 System.out.println(e);
}
}
//2 public static int doIt() throws Exception
{
//3 throw new Exception("Forget It");
}
}
The output of the above code is java.lang.Exception Forget it.I don't how the Forget it in doIt() printed out.Can anyone explain me.

Thanks
sudha

Follow the red number... t
This (d* doIt()), calls the doIt() method that throws Exception.
In the method, it throw new Exception("Forget It"). So there is a exception and since doIt() throws exception (this means let the method which called doIt() to handle the exception) it goes back to main() which catch the exception with catch (Exception e){ }.
The it just print it out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception