Can anyone please explain why the Example 1 posted below compiles and runs and the the Example 2 does not compile?
Example :1
public class AQuestion
{
public static void main(
String args[])
{
System.out.println("Before Try");
try
{
}
catch(Throwable t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
This compiles and prints "Before Try" and "At the End".
Example : 2
public class AQuestion
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(java.io.IOException t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
gives a compiler error.
Compiler error complaining about the catch block where no IOException object can ever be thrown.
Thanks,
Sunitha. S