import java.io.*;
import java.io.IOException;
public class TestException {
public static void main(String[] args)
{
try
{
test();
}
catch(FileNotFoundException e)
{
System.out.println("Error in FileNotFoundException!");
}
catch(IOException e)
{
System.out.println("Error in IOException....");
}
try
{
FileInputStream fileObject = new FileInputStream("myfile.txt");
int len=fileObject.read();
System.out.println(len);
int div=0;
IOException e=new IOException();
throw e;//此行之后不能有代码,否则无效,提示出错
/*(int res=10/div;
System.out.println(res);*/
}
catch(IOException e)
{
System.out.println("Error in FileInputStream.");
}
catch(Exception e)
{
System.out.println("Error in div by zero.");
}
finally
{
System.out.println("Block in Finally...");
}
}
public static void test()
throws FileNotFoundException,IOException //要在自定义的函数里面抛出异常必须不能少了这行
{
if (1==1)
{
FileNotFoundException e=new FileNotFoundException();
throw e;
}
else
{
IOException e2=new IOException();
throw e2;
}
}
}
import java.io.IOException;
public class TestException {
public static void main(String[] args)
{
try
{
test();
}
catch(FileNotFoundException e)
{
System.out.println("Error in FileNotFoundException!");
}
catch(IOException e)
{
System.out.println("Error in IOException....");
}
try
{
FileInputStream fileObject = new FileInputStream("myfile.txt");
int len=fileObject.read();
System.out.println(len);
int div=0;
IOException e=new IOException();
throw e;//此行之后不能有代码,否则无效,提示出错
/*(int res=10/div;
System.out.println(res);*/
}
catch(IOException e)
{
System.out.println("Error in FileInputStream.");
}
catch(Exception e)
{
System.out.println("Error in div by zero.");
}
finally
{
System.out.println("Block in Finally...");
}
}
public static void test()
throws FileNotFoundException,IOException //要在自定义的函数里面抛出异常必须不能少了这行
{
if (1==1)
{
FileNotFoundException e=new FileNotFoundException();
throw e;
}
else
{
IOException e2=new IOException();
throw e2;
}
}
}