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.