• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic