A
asit
Consider the following code snippets
import java.io.*;
public class MyQuestion1 {
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");
}
}
This shows following compiler error,
exception java.io.IOException is never thrown in body of corresponding
try statement
But why the following code is error free
public class MyQuestion2 {
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");
}
}
import java.io.*;
public class MyQuestion1 {
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");
}
}
This shows following compiler error,
exception java.io.IOException is never thrown in body of corresponding
try statement
But why the following code is error free
public class MyQuestion2 {
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");
}
}