This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

exception

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody explain why the first compiles, the second doesn't?
<code>
first


import java.io.*;
public class AQuestion
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(Exception t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
second
import java.io.IOException;
public class AQuestion
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(IOException t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}


</code>
Thanks
Jason
 
Ranch Hand
Posts: 2378
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jason,
Possibly because every catch block checks whether any kind of Exception that it can catch is ever throwable by the corresponding try block or in the stack trace. Mayy be the check is not done on Throwable and Exception class only.
In ur second blank try block there can never be an IOException throwable.Better solution by someone else.....
------------------
azaman
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IOException is a checked exception , so you have to throw it explicitly to catch it.
reply
    Bookmark Topic Watch Topic
  • New Topic