R
Razvan
Hi !
Take a look at the following code:
class SimpleJava
{
public static void main(String args[])
{
System.out.println("SimpleJava ....");
SimpleJava sj = new SimpleJava();
System.out.println("Before.");
try {
}
catch(Exception ee) {
System.out.println("Exception caught !");
}
System.out.println("After.");
}
}
It compiles and runs as expected.
Now try this one:
import java.io.*;
class SimpleJava
{
public static void main(String args[])
{
System.out.println("SimpleJava ....");
SimpleJava sj = new SimpleJava();
System.out.println("Before.");
try {
}
catch(IOException ee) {
System.out.println("Exception caught !");
}
System.out.println("After.");
}
}
The second version does not compile ! Compiler error:
SimpleJava.java:19: exception java.io.IOException is never thrown in
body of corresponding try statement
catch(IOException ee) {
Compiler error or expected behavior ?
Regards,
Razvan
Take a look at the following code:
class SimpleJava
{
public static void main(String args[])
{
System.out.println("SimpleJava ....");
SimpleJava sj = new SimpleJava();
System.out.println("Before.");
try {
}
catch(Exception ee) {
System.out.println("Exception caught !");
}
System.out.println("After.");
}
}
It compiles and runs as expected.
Now try this one:
import java.io.*;
class SimpleJava
{
public static void main(String args[])
{
System.out.println("SimpleJava ....");
SimpleJava sj = new SimpleJava();
System.out.println("Before.");
try {
}
catch(IOException ee) {
System.out.println("Exception caught !");
}
System.out.println("After.");
}
}
The second version does not compile ! Compiler error:
SimpleJava.java:19: exception java.io.IOException is never thrown in
body of corresponding try statement
catch(IOException ee) {
Compiler error or expected behavior ?
Regards,
Razvan