代码改变世界

异常课——抛出

2016-09-26 13:49  宇航员舒克  阅读(121)  评论(0编辑  收藏  举报
package class10923;
									//异常课件例题——抛出
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.synth.SynthScrollBarUI;

public class yichangpaochu {
												//抛出语句
	public static void main(String[] args) //throws FileNotFoundException 
	{
		// TODO Auto-generated method stub

		//访问文件
//		File file=new File("d:/a.test");
		//使用输入流打开文件
//		FileInputStream in =new FileInputStream(file);
		
//		
//			try {
//				System.out.println(chufa(12, 0));
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//				System.out.println("错误");
//			}

	}
	
	//抛出异常的方法
	public static int chufa(int a,int b) throws Exception
	{
//		if(b==0)
//		{
//			//抛出异常语句
//			//Exceptin的实例
//			throw new Exception("你传的参数b不能等于0");
//		}
		int rtn=0;
		try
		{
			rtn=a/b;
		}
		catch(Exception e)
		{
			//记录异常信息
			
			//继续抛出
			throw e;
		}
		return rtn;
//		return a/b;
	}

}